Skip to content

Commit cb3559d

Browse files
committed
新增menu示例
1 parent 3296e73 commit cb3559d

File tree

3 files changed

+67
-19
lines changed

3 files changed

+67
-19
lines changed

app/src/main/java/org/evilbinary/tv/DemoMenuActivity.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class DemoMenuActivity extends Activity {
2828

2929
};
3030

31-
private MyAdapter secondAdapter;
31+
private MyAdapter secondAdapter;
32+
private View lastFocus = null;
3233

3334
@Override
3435
protected void onCreate(Bundle savedInstanceState) {
@@ -42,33 +43,40 @@ protected void onCreate(Bundle savedInstanceState) {
4243
RecyclerView firstRecyclerView = (RecyclerView) findViewById(R.id.firstRecyclerView);
4344
RecyclerView secondRecyclerView = (RecyclerView) findViewById(R.id.secondRecyclerView);
4445

45-
GridLayoutManager layoutManager = new GridLayoutManager(this,1);
46+
GridLayoutManager layoutManager = new GridLayoutManager(this, 1);
4647
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
4748
firstRecyclerView.setLayoutManager(layoutManager);
4849
firstRecyclerView.setFocusable(false);
4950

5051

51-
52-
GridLayoutManager layoutManager2 = new GridLayoutManager(this,1);
52+
GridLayoutManager layoutManager2 = new GridLayoutManager(this, 1);
5353
layoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
5454
secondRecyclerView.setLayoutManager(layoutManager2);
5555
secondRecyclerView.setFocusable(false);
5656

5757

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

6161

6262
// 创建Adapter,并指定数据集
63-
MyAdapter adapter = new MyAdapter(this, mCategory,R.layout.item_menu,new View.OnFocusChangeListener(){
64-
63+
MyAdapter adapter = new MyAdapter(this, mCategory, R.layout.item_menu, new View.OnFocusChangeListener() {
6564
@Override
6665
public void onFocusChange(View v, boolean hasFocus) {
67-
if(hasFocus) {
66+
if (hasFocus) {
6867
int pos = (int) v.getTag();
6968
secondAdapter.setData(mDatas[pos]);
7069
secondAdapter.notifyDataSetChanged();
71-
Log.d("tt", "onFocusChange===>"+pos);
70+
Log.d("tt", "onFocusChange===>" + pos);
71+
72+
if(lastFocus!=null)
73+
lastFocus.setBackgroundResource(R.drawable.list_item_shape);
74+
lastFocus = v;
75+
v.setBackgroundResource(R.drawable.shape);
76+
77+
78+
} else {
79+
//v.setBackgroundColor(Color.RED);
7280
}
7381
}
7482
});
@@ -81,11 +89,7 @@ public void onFocusChange(View v, boolean hasFocus) {
8189
border.attachTo(secondRecyclerView);
8290

8391

84-
8592
}
8693

8794

88-
89-
90-
9195
}

app/src/main/res/layout/demo_list_view.xml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
55
android:layout_margin="10dp"
6-
7-
android:orientation="vertical">
6+
android:gravity="center"
7+
android:orientation="horizontal">
88

99

1010
<ListView
11+
1112
android:id="@+id/listView"
1213
android:layout_width="400dp"
1314
android:layout_height="wrap_content"
@@ -19,12 +20,25 @@
1920
android:paddingRight="10dp"
2021

2122
android:dividerHeight="8dp"
22-
android:drawSelectorOnTop="false"
23-
24-
android:focusable="false"
25-
android:listSelector="#00000000"
23+
android:drawSelectorOnTop="true"
2624

2725
android:scrollbars="none" />
2826

27+
<ListView
28+
android:id="@+id/listView2"
29+
android:layout_width="400dp"
30+
android:layout_height="wrap_content"
31+
android:layout_gravity="center"
32+
android:clipChildren="false"
33+
android:clipToPadding="false"
34+
android:divider="@null"
35+
android:paddingLeft="10dp"
36+
android:paddingRight="10dp"
37+
38+
android:dividerHeight="8dp"
39+
android:drawSelectorOnTop="true"
40+
41+
android:scrollbars="none" />
42+
<!--android:listSelector="#00000000"-->
2943

3044
</LinearLayout>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="300dp"
4+
android:layout_height="80dp"
5+
android:layout_gravity="center"
6+
android:background="@drawable/list_item_shape"
7+
android:focusable="true"
8+
android:gravity="left">
9+
10+
11+
<TextView
12+
android:layout_marginLeft="15dp"
13+
android:id="@+id/textView"
14+
android:layout_width="wrap_content"
15+
android:layout_height="80dp"
16+
android:layout_alignParentEnd="true"
17+
android:layout_alignParentRight="true"
18+
android:layout_alignParentTop="true"
19+
android:layout_gravity="left"
20+
android:layout_toEndOf="@+id/imageView"
21+
android:layout_toRightOf="@+id/imageView"
22+
android:focusable="false"
23+
android:gravity="center"
24+
android:text="ddd"
25+
android:textAlignment="center"
26+
android:textColor="@color/white"
27+
android:textSize="24sp" />
28+
29+
30+
</RelativeLayout>

0 commit comments

Comments
 (0)