主Activity
public class MainActivity extends AppCompatActivity { private ListView lv; private DrawerLayout drawerLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init() { drawerLayout = (DrawerLayout) findViewById(R.id.mydraw); lv = (ListView) findViewById(R.id.lv); //点击lv的条目,关闭侧滑,在主界面显示相关详细 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawerLayout.closeDrawer(lv);//关闭侧滑 //改变主界面 String str = parent.getItemAtPosition(position).toString(); } }); } }
布局
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mydraw" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lv" android:layout_width="240sp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="#f00" android:dividerHeight="1dp" android:background="#fff" /> </android.support.v4.widget.DrawerLayout>
6532

被折叠的 条评论
为什么被折叠?



