카테고리 보관물: Android

Android

다른 조각 문제에 대한 조각 다른 조각 (메인이라고

하나의 조각을 표시 할 때 (이것은 전체 화면 #77000000 배경 )을 다른 조각 (메인이라고 함) 위에 메인 조각은 여전히 ​​클릭에 반응합니다 (보이지 않아도 버튼을 클릭 할 수 있음).

질문 : 첫 번째 (주) 조각에서 클릭을 방지하는 방법은 무엇입니까?

편집하다

불행히도, 두 번째 조각에 투명한 배경을 사용하기 때문에 주요 조각을 숨길 수 없습니다 (따라서 사용자는 뒤에있는 것을 볼 수 있습니다).



답변

설정 clickabletrue로 두 번째 조각의 뷰 속성입니다. 뷰는 이벤트를 잡아서 주요 조각으로 전달되지 않습니다. 따라서 두 번째 조각의 뷰가 레이아웃 인 경우 코드는 다음과 같습니다.

<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>


답변

두 개의 프래그먼트가 동일한 컨테이너보기에 배치 된 경우 두 번째 프래그먼트를 표시 할 때 첫 번째 프래그먼트를 숨겨야합니다.

Fragment에 대한 문제를 해결하는 방법에 대한 자세한 내용을 보려면 내 라이브러리를 참조하십시오 : 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키보드와 같은 입력 장치에서 포커스를 얻을 수 있음을 의미합니다. 키보드와 같은 입력 장치는 입력 자체를 기반으로 입력 이벤트를 보낼 뷰를 결정할 수 없으므로 포커스가있는 뷰로 보냅니다.


답변

우리 중 일부 가이 스레드에 기여한 솔루션이 두 개 이상 있지만 다른 솔루션을 언급하고 싶습니다. 클릭과 포커스를 두는 것을 좋아하지 않는다면 나와 같은 XML의 모든 레이아웃의 루트 ViewGroup과 같습니다. 아래와 같은 것을 가지고 있다면베이스에 놓을 수도 있습니다.

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 또는 VISIBLE로 설정해야 할 수도 있습니다.

코 틀린에서 :

fragmentManager.findFragmentByTag(BottomFragment.TAG).view.visibility = GONE

이 솔루션은 애니메이션을 사용할 때 의 대안 hide()show()방법 보다 선호됩니다 FragmentTransaction. 당신은 방금에서 호출 onTransitionStart()onTransitionEnd()Transition.TransitionListener.