다른 조각 문제에 대한 조각
한 조각을 보여줄 때(전체 화면에 표시됨)#77000000
background) 다른 fragment(background) 위에, 내 메인 fragment는 여전히 클릭에 반응합니다(우리가 보지 않더라도 버튼을 클릭할 수 있습니다).
질문: 첫 번째 (주) 조각에 대한 클릭을 방지하는 방법은 무엇입니까?
편집
안타깝게도, 저는 두 번째 조각에 투명 배경을 사용하고 있기 때문에 주요 조각을 숨길 수 없습니다(사용자는 뒤에 무엇이 있는지 볼 수 있습니다).
세트clickable
두 번째 조각의 true 보기 속성입니다.보기는 이벤트를 캡처하여 기본 조각으로 전달되지 않도록 합니다.따라서 두 번째 조각의 보기가 레이아웃이면 다음과 같은 코드가 됩니다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
해결책은 매우 간단합니다.우리의 두 번째 조각(우리의 주요 조각과 겹치는 부분)에서 우리는 잡기만 하면 됩니다.onTouch
이벤트:
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstance){
View root = somehowCreateView();
/*here is an implementation*/
root.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
return root;
}
그냥 추가clickable="true"
그리고.focusable="true"
상위 레이아웃으로
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true">
<!--Your views-->
</android.support.constraint.ConstraintLayout>
사용 중인 경우AndroidX
이것을 먹어보세요.
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true">
<!--Your views-->
</androidx.constraintlayout.widget.ConstraintLayout>
두 조각이 동일한 컨테이너 보기에 배치된 경우 두 번째 조각을 표시할 때 첫 번째 조각을 숨겨야 합니다.
프래그먼트에 대한 문제를 해결하는 방법에 대한 더 많은 질문을 알고 싶다면, 제 라이브러리를 보실 수 있습니다: https://github.com/JustKiddingBaby/FragmentRigger
FirstFragment firstfragment;
SecondFragment secondFragment;
FragmentManager fm;
FragmentTransaction ft=fm.beginTransaction();
ft.hide(firstfragment);
ft.show(secondFragment);
ft.commit();
추가해야 합니다.android:focusable="true"
와 함께android:clickable="true"
Clickable
포인터 장치로 클릭하거나 터치 장치로 탭할 수 있음을 의미합니다.
Focusable
키보드와 같은 입력 장치에서 포커스를 얻을 수 있음을 의미합니다.키보드와 같은 입력 장치는 입력 자체를 기준으로 입력 이벤트를 보낼 뷰를 결정할 수 없으므로 포커스가 있는 뷰로 전송합니다.
방법 1:
모든 조각 레이아웃에 추가할 수 있습니다.
android:clickable="true"
android:focusable="true"
android:background="@color/windowBackground"
방법 2: (프로그래밍 방식으로)
모든 조각 확장 대상FragmentBase
기타. 그런 다음 이 코드를 에 추가합니다.FragmentBase
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getView().setBackgroundColor(getResources().getColor(R.color.windowBackground));
getView().setClickable(true);
getView().setFocusable(true);
}
우리 중 일부가 이 스레드에 기여한 솔루션은 두 가지가 아니지만 다른 솔루션도 하나 언급하고 싶습니다.클릭할 수 있고 초점을 맞출 수 있는 기능을 넣는 것이 싫다면 저처럼 XML의 모든 레이아웃의 루트 ViewGroup에 true와 같습니다.또한 아래와 같은 것이 있으면 베이스에 넣을 수 있습니다.
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) : View? {
super.onCreateView(inflater, container, savedInstanceState)
val rootView = inflater.inflate(layout, container, false).apply {
isClickable = true
isFocusable = true
}
return rootView
}
인라인 변수도 사용할 수 있지만 개인적인 이유로 선호하지 않았습니다.
레이아웃 XML을 싫어하는 사람들에게 도움이 되었으면 합니다.
허용 가능한 답변은 "작동"하지만, 하단의 단편이 여전히 그려지고 있기 때문에 성능 비용(초과 인출, 방향 변경 시 재측정)도 발생합니다.태그나 ID로 단편을 찾고 다시 표시해야 할 때 가시성을 GONE 또는 VISIVE로 설정하면 됩니다.
코틀린에서:
fragmentManager.findFragmentByTag(BottomFragment.TAG).view.visibility = GONE
이 솔루션이 대안보다 더 바람직합니다.hide()
그리고.show()
의 FragmentTransaction
애니메이션을 사용할 때.당신은 그냥 그것을 전화로.onTransitionStart()
그리고.onTransitionEnd()
Transition.TransitionListener
.
할 수 속성을 사용하여 프래그먼트의 줄 수 활동 에 함수 " " " " " 를 할 수 있습니다.doNothing(View view)
그리고 그 안에 아무것도 쓰지 마세요.이것으로 충분합니다.
DialogFragment의 경우처럼 들립니다.그렇지 않으면 Fragment Manager를 사용하여 하나는 숨기고 다른 하나는 표시하도록 커밋합니다.그것은 저에게 효과가 있었습니다.
의 android:clickable="true"
.이 솔루션은 상위 레이아웃인 경우 코디네이터 레이아웃에서 작동하지 않습니다.저는 을 부모 레이아웃으로 "RelativeLayout"을 추가했습니다.android:clickable="true"
코디네이터 레이아웃은 Relative Layout입니다.
같은 xml을 가진 여러 개의 fragment가 있었습니다.
시간을 에, 는 몇시을보후에낸, 제습다니했거저는간다니를 제거했습니다.setPageTransformer
그리고 그것은 작동하기 시작했습니다.
// viewpager.setPageTransformer(false, new BackgPageTransformer())
나는 논리적으로 판단했습니다.
public class BackgPageTransformer extends BaseTransformer {
private static final float MIN_SCALE = 0.75f;
@Override
protected void onTransform(View view, float position) {
//view.setScaleX Y
}
@Override
protected boolean isPagingEnabled() {
return true;
}
}
언급URL : https://stackoverflow.com/questions/10389620/fragment-over-another-fragment-issue
'programing' 카테고리의 다른 글
mysqdump에서 생성된 /*!xxxxxx 문 */의 의미는 무엇입니까? (0) | 2023.08.30 |
---|---|
단추를 풀 너비로 설정하시겠습니까? (0) | 2023.08.30 |
서비스를 시작한 후 도커 컨테이너를 계속 실행하는 방법은 무엇입니까? (0) | 2023.08.30 |
결과 집합을 10개 그룹으로 분할 (0) | 2023.08.30 |
jQuery.each()의 각 반복 사이에 일시 중지를 추가하는 방법은 무엇입니까? (0) | 2023.08.30 |