簡體   English   中英

相對布局的Android導航抽屜

[英]Android navigation drawer in releative layout

我正在工作導航抽屜。我成功創建了我的導航抽屜和程序。 現在我想將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之上?

這是您更新的代碼:

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

您可以在標題ListView上添加editText

我認為這不是一個好主意。 如果該文本字段對於所有片段都是公用的,則應考慮將其放在ActionBar中

使用Linearlayout在列表視圖上方添加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>
  <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM