【问题标题】:DrawerLayout with input widgets带有输入小部件的 DrawerLayout
【发布时间】:2014-10-13 07:11:20
【问题描述】:

我在我的 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;
    }

有什么想法吗?

【问题讨论】:

    标签: android android-widget navigation-drawer


    【解决方案1】:

    我无法在 EditText 小部件之间切换。当我单击一些小部件时 滑动布局开始折叠。

    因为您的小部件位于主布局上,而那些不在滑动菜单上。因此,当您单击它们时,这意味着您在抽屉布局之外单击,您的布局不正确试试这个:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      相关资源
      最近更新 更多