2016-11-04 11 views
4

これは私が発見した奇妙なバグのようなものです。DrawerLayoutが終了したときにRecyclerViewがフォーカスされる

しかし、私がフラグメント内にRecyclerViewを持っていて、DrawerLayoutを開いてRecyclerViewにフォーカスがあります。つまり、DrawerLayoutを閉じると、ScrollViewがRecyclerViewにジャンプします。明らかに、私は、DrawerLayoutが閉じられたときにScrollViewの位置が動かないようにしたいと思います。私のRecyclerViewでは決して解決しません。私のアプリケーションを通じて


CODE

、私は、このセットアップに似ScrollViews内に含まれるRecyclerViews、持っている:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <RelativeLayout 
      android:layout_alignParentTop="true" 
      android:layout_width="match_parent" 
      android:layout_height="180dp"> 

      <android.support.v7.widget.AppCompatImageView 
       android:id="@+id/header_photo" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:adjustViewBounds="true" 
       android:tint="#80000000" 
       android:scaleType="centerCrop"/> 

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_centerHorizontal="true"> 

       <TextView android:id="@+id/header_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:gravity="center" 
        android:paddingTop="2dp" 
        android:paddingBottom="2dp" 
        android:textColor="@color/text_SecondaryColor" 
        android:textSize="@dimen/header_xxlarge"/> 

       <View android:id="@+id/divider" 
        android:layout_width="0dp" 
        android:layout_height="@dimen/hr_thick" 
        android:background="@color/accent_PrimaryColor"/> 
      </LinearLayout> 
     </RelativeLayout> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_margin="20dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerview" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 

      <Button android:id="@+id/button_more" 
       android:layout_marginTop="6dp" 
       android:layout_marginBottom="6dp" 
       android:layout_width="400px" 
       android:layout_height="100px" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:background="@drawable/button_dark" 
       android:textColor="@drawable/button_dark_textcolor"/> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

をそして、私のDrawerLayoutのXMLの設計は、次のように配置されている:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <include 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       layout="@layout/toolbar" /> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/contentframe" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="300dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/background_Secondary"> 

     <!-- Relative Layout : Back Button --> 
     <RelativeLayout 
      android:id="@+id/menu_backcontainer" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize"> 

      <ImageView 
       android:id="@+id/menu_back" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="20dp" 
       android:src="@drawable/angle" 
       android:layout_centerVertical="true" 
       android:layout_alignParentEnd="true" /> 
     </RelativeLayout> 

     <!-- List View : Menu Drawer Content --> 
     <ListView 
      android:id="@+id/menu" 
      android:layout_below="@id/menu_backcontainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:choiceMode="singleChoice" 
      android:background="@color/background_PrimaryDarkColor"> 
     </ListView> 
    </RelativeLayout> 
</android.support.v4.widget.DrawerLayout> 

私はここに含める必要がある他のどのようなJavaコードを確認していないが、これは私が私のRecyclerViewインスタンス化する方法です:

recyclerView = (RecyclerView)view.findViewById(R.id.recyclerview); 
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext().getApplicationContext()); 
    recyclerView.setLayoutManager(layoutManager); 
    recyclerView.setNestedScrollingEnabled(false); 

をそして私のDrawerLayoutについて:

drawerlayout = (DrawerLayout)findViewById(R.id.drawer); 
menu = (ListView)findViewById(R.id.menu); 
MenuAdapter adapter = new MenuAdapter(
     this, 
     R.layout.listview_menuitem, 
     menuItemArray); 
menu.setAdapter(adapter); 
menu.setOnItemClickListener(new menuItemClickListener()); 

menuToggle = new ActionBarDrawerToggle(
     this, 
     drawerlayout, 
     toolbar, 
     R.string.app_name, 
     R.string.app_name); 
    drawerlayout.setDrawerListener(menuToggle); 
    menuToggle.syncState(); 

答えて

0

うわあ、それはどのような瞬間素晴らしいですコンピュータから離れてコーヒーを飲むことができます。

私のFrameLayoutのfocusableInTouchMode属性をtrueに設定するだけです。

これは、DrawerLayoutを開いた後に画面のどこに触れたとしても、RecyclerViewsがScrollViewのフォーカス要素になることを拒否していると思います。おそらくもっと良い、より完全な説明があります。しかし、私はこれがこの問題を経験するかもしれない誰かを助けることを願っています。

関連する問題