我在Android应用程序上工作,我想用滑动子视图创建一个视图。子视图将包含一些小部件,例如EditText。这是我的布局文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:background="#0000ff">
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
我无法在EditText小部件之间切换。当我点击某个小部件时,滑动布局开始崩溃。我认为这是导致我的问题,但我使用以下代码。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
DrawerLayout drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
return view;
}
左侧布局已锁定,但我仍然无法在小部件之间切换。我也试图改变可点击和可聚焦的属性。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
DrawerLayout drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
drawerLayout.setClickable(true);
drawerLayout.setFocusable(true);
return view;
}
有什么想法吗?
答案 0 :(得分:1)
我无法在EditText小部件之间切换。当我点击一些小部件时 滑动布局开始崩溃。
因为您的小部件位于主布局上,而这些小部件不在滑动菜单上。所以当你点击它们就意味着你点击了drawerlayout外面,你的布局不正确试试这个:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
</FrameLayout>
<LinearLayout android:layout_width="250dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:background="#0000ff">
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>