请求关注片段

时间:2016-09-21 09:26:09

标签: android android-fragments d-pad

我正在为Android TV开发应用。在应用程序中,片段布局在ImageView水平方向上有四个LinearLayout,在RecyclerView下方有一个LinearLayout。当我启动应用并浏览DPAD控件时,RecyclerView向上和向下导航。要求是默认情况下,首先ImageView LinearLayout的{​​{1}}片段将被选中。在我们按下DPAD的右键后,然后选择下一个ImageView。当我们按下键时,焦点将移至RecyclerView。当焦点位于RecyclerView第一个孩子时,我们按向上键,然后重点移动Imageview LinearLayout的{​​{1}}。

我也使用了imageview.requestFocus()但它无法正常工作。请帮帮我。

以下是我的布局文件

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

<LinearLayout 
       android:id="@+id/home_fragment_menu_container"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
       android:layout_marginLeft="30dp"
       android:layout_marginRight="30dp"
       android:layout_marginBottom="10dp">


       <ImageView 
           android:id="@+id/img_playall"
           style="@style/home_fragment_menu"
           android:src="@drawable/play_all"
           android:focusable="true"
           android:focusableInTouchMode="true"/>

       <ImageView 
           android:id="@+id/img_trending"
           style="@style/home_fragment_menu"
           android:src="@drawable/trending"/>

       <ImageView 
           android:id="@+id/img_search"
           style="@style/home_fragment_menu"
           android:src="@drawable/search"/>

       <ImageView 
           android:id="@+id/img_setting"
           style="@style/home_fragment_menu"
           android:src="@drawable/settings"/>    
   </LinearLayout>


   <LinearLayout 
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_below="@+id/home_fragment_menu_container"
       android:layout_marginLeft="45dp"
       >

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

   </LinearLayout>
</RelativeLayout>

下面是fragment.java文件

public class HomeFragment extends Fragment {

    private static final String TAG = "HomeFragment";

    ImageView playAllImage, trendingImage, searchImage, settingImage;



    Context context;
    RecyclerView verticalList;
    ArrayList<ArrayList<VideoContentModel>> categoriesVideoList;
    ArrayList<CategoryModel> categoryDataList;

    public static HomeFragment newInstance(Context context, ArrayList<ArrayList<VideoContentModel>> categoriesVideoList,
            ArrayList<CategoryModel> categoryDataList){

        HomeFragment fragment = new HomeFragment();
        fragment.context = context;
        fragment.categoriesVideoList = categoriesVideoList;
        fragment.categoryDataList = categoryDataList;

        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.home_fragment_layout, container, false);

        playAllImage = (ImageView)view.findViewById(R.id.img_playall);
        trendingImage = (ImageView)view.findViewById(R.id.img_trending);
        searchImage = (ImageView)view.findViewById(R.id.img_search);
        settingImage = (ImageView)view.findViewById(R.id.img_setting);

        playAllImage.requestFocus();


        verticalList = (RecyclerView)view.findViewById(R.id.vertical_recyclerview);
        verticalList.setHasFixedSize(true);
        verticalList.setLayoutManager(new LinearLayoutManager(context));
        CatListVerticalAdapter adapter = new CatListVerticalAdapter(context,categoriesVideoList,categoryDataList);
        verticalList.setAdapter(adapter);

        verticalList.clearFocus();



        //


        if(playAllImage.hasFocus())
            Log.i(TAG,"play all has focus");
        else
            Log.i(TAG,"===playall has not focus");

        return view;
    }

我们如何通过DPAD超越要求?请帮帮我..

0 个答案:

没有答案