Skip to content

Commit

Permalink
新增menu示例
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbinary committed Apr 10, 2016
1 parent 3296e73 commit cb3559d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
30 changes: 17 additions & 13 deletions app/src/main/java/org/evilbinary/tv/DemoMenuActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class DemoMenuActivity extends Activity {

};

private MyAdapter secondAdapter;
private MyAdapter secondAdapter;
private View lastFocus = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -42,33 +43,40 @@ protected void onCreate(Bundle savedInstanceState) {
RecyclerView firstRecyclerView = (RecyclerView) findViewById(R.id.firstRecyclerView);
RecyclerView secondRecyclerView = (RecyclerView) findViewById(R.id.secondRecyclerView);

GridLayoutManager layoutManager = new GridLayoutManager(this,1);
GridLayoutManager layoutManager = new GridLayoutManager(this, 1);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
firstRecyclerView.setLayoutManager(layoutManager);
firstRecyclerView.setFocusable(false);



GridLayoutManager layoutManager2 = new GridLayoutManager(this,1);
GridLayoutManager layoutManager2 = new GridLayoutManager(this, 1);
layoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
secondRecyclerView.setLayoutManager(layoutManager2);
secondRecyclerView.setFocusable(false);


secondAdapter=new MyAdapter(this,new String[]{},R.layout.item_menu);
secondAdapter = new MyAdapter(this, new String[]{}, R.layout.item_menu_sub);
secondRecyclerView.setAdapter(secondAdapter);


// 创建Adapter,并指定数据集
MyAdapter adapter = new MyAdapter(this, mCategory,R.layout.item_menu,new View.OnFocusChangeListener(){

MyAdapter adapter = new MyAdapter(this, mCategory, R.layout.item_menu, new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
if (hasFocus) {
int pos = (int) v.getTag();
secondAdapter.setData(mDatas[pos]);
secondAdapter.notifyDataSetChanged();
Log.d("tt", "onFocusChange===>"+pos);
Log.d("tt", "onFocusChange===>" + pos);

if(lastFocus!=null)
lastFocus.setBackgroundResource(R.drawable.list_item_shape);
lastFocus = v;
v.setBackgroundResource(R.drawable.shape);


} else {
//v.setBackgroundColor(Color.RED);
}
}
});
Expand All @@ -81,11 +89,7 @@ public void onFocusChange(View v, boolean hasFocus) {
border.attachTo(secondRecyclerView);



}





}
26 changes: 20 additions & 6 deletions app/src/main/res/layout/demo_list_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"

android:orientation="vertical">
android:gravity="center"
android:orientation="horizontal">


<ListView

android:id="@+id/listView"
android:layout_width="400dp"
android:layout_height="wrap_content"
Expand All @@ -19,12 +20,25 @@
android:paddingRight="10dp"

android:dividerHeight="8dp"
android:drawSelectorOnTop="false"

android:focusable="false"
android:listSelector="#00000000"
android:drawSelectorOnTop="true"

android:scrollbars="none" />

<ListView
android:id="@+id/listView2"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipChildren="false"
android:clipToPadding="false"
android:divider="@null"
android:paddingLeft="10dp"
android:paddingRight="10dp"

android:dividerHeight="8dp"
android:drawSelectorOnTop="true"

android:scrollbars="none" />
<!--android:listSelector="#00000000"-->

</LinearLayout>
30 changes: 30 additions & 0 deletions app/src/main/res/layout/item_menu_sub.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:background="@drawable/list_item_shape"
android:focusable="true"
android:gravity="left">


<TextView
android:layout_marginLeft="15dp"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="left"
android:layout_toEndOf="@+id/imageView"
android:layout_toRightOf="@+id/imageView"
android:focusable="false"
android:gravity="center"
android:text="ddd"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="24sp" />


</RelativeLayout>

0 comments on commit cb3559d

Please sign in to comment.