relativelayout中的Android导航抽屉

时间:2014-06-17 09:41:48

标签: android navigation-drawer

我工作导航抽屉。我成功创建了我的导航抽屉和程序工作。 现在我想将activity_main.xml文件中的Edittext添加到ListView以上。这是我的activity_main.xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:orientation="vertical" >

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

    <EditText
        android:id="@+id/card_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dip"
        android:gravity="center"
        android:hint="Enter text"
        android:padding="10dip"
        android:singleLine="true"
        android:textSize="15dp" />

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#191919"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>

如何将edittext添加到listview之上?

5 个答案:

答案 0 :(得分:1)

这是您更新的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff0000"
    android:orientation="vertical" >

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </FrameLayout>

        <LinearLayout
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/editField"
                android:layout_width="match_parent"
                android:layout_height="40dp" />

            <ListView
                android:id="@+id/left_drawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#191919"
                android:choiceMode="singleChoice"
                android:divider="@android:color/transparent"
                android:dividerHeight="0dp" />
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

答案 1 :(得分:0)

您可以在Header ListView

上添加editText

答案 2 :(得分:0)

我不认为这是个好主意。如果该文本字段对于所有片段都是通用的,那么您应该考虑将其放在ActionBar中。

答案 3 :(得分:0)

使用Linearlayout在listview上方添加edittext

 <LinearLayout 
            android:id="@+id/drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:background="@android:color/darker_gray"
            android:layout_gravity="start" >

            <EditText 
                android:id="@+id/searchView"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:gravity="center"
                android:textSize="20sp"
                android:hint="Search"            
                android:imeOptions="actionSearch"
                android:imeActionLabel="Search"            
                android:drawableRight="@drawable/ic_action_search"   >          
             </EditText>   

            <ListView
                android:id="@+id/left_drawer"
                android:layout_width="240dp"
                android:layout_height="match_parent"
                android:layout_gravity="start"            
                android:choiceMode="singleChoice" />   

        </LinearLayout>

答案 4 :(得分:-1)

  <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com /apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer"

>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:orientation="vertical">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/content_menu"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"

        />



</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="100">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->



    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"


        />

    <EditText
        android:id="@+id/card_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:layout_margin="10dip"


        android:gravity="left"
        android:hint="Enter text"

        android:padding="10dip"
        android:singleLine="true"

        android:textSize="15dp"

        />


</RelativeLayout>

<include layout="@layout/adapter_drawer" />


</android.support.v4.widget.DrawerLayout>

您的adapter_drawer.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/left_drawer"
   android:layout_width="wrap_content"
   android:layout_height="match_parent"
   android:layout_gravity="start"
   android:background="@color/red"
>

 <EditText
       android:id="@+id/card_number"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:layout_margin="10dip"


        android:gravity="left"
        android:hint="Enter text"

        android:padding="10dip"
        android:singleLine="true"

        android:textSize="15dp"

        />

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >


    <RelativeLayout
        android:id="@+id/row_1"
        android:layout_width="wrap_content"
        android:layout_height="100dip"
        android:gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_weight="20">


        <ImageView
            android:id="@+id/picture_1"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="@dimen/space_2_x"

            android:clickable="true"
            android:contentDescription="@string/app_name"
            android:padding="@dimen/space_2_x"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_launcher"


            />


        <TextView
            android:id="@+id/text_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/picture_1"
            android:layout_centerHorizontal="true"
            android:clickable="true"

            android:gravity="center"
            android:text="Home"
            android:textColor="@color/white"
            android:textSize="@dimen/text_size_small"


            />
    </RelativeLayout>
  </RelativeLayout>