代码之家  ›  专栏  ›  技术社区  ›  Suhas

编辑文本和一个按钮,后跟回收器视图

  •  2
  • Suhas  · 技术社区  · 9 年前

    我有一个空的 Activity 具有 RelativeLayout 和 RecyclerView

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:="match_parent"
       android:layout_height="match_parent"
       app:layout_behavilayout_widthor="@string/appbar_scrolling_view_behavior"
       tools:showIn="@layout/activity_main"
       tools:context=".MainActivity">
    
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    </RelativeLayout>
    

    我需要一个 EditText 回收视图 . RecyclerView's 填充高度应该更改,但不确定!请帮帮我

    5 回复  |  直到 9 年前
        1
  •  2
  •   debugger    9 年前

    试试这个。将父布局设置为线性布局,视图将堆叠。

    <?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:padding="5dp">
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name"
                android:layout_toStartOf="@+id/button" />
    
            <Button
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" 
                android:layout_alignParentEnd="true"/>
        </RelativeLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </LinearLayout>
    
        2
  •  2
  •   IntelliJ Amiya    9 年前
    • "Vertical" 方向
    • 使用 android:layout_weight 所有物

    指示在LinearLayout中分配了多少额外空间 与这些布局参数关联的视图。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <EditText
            android:id="@+id/et_ONE"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <Button
            android:id="@+id/button_ONE"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button"
            android:layout_weight="1"/>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="3"/>
    
    
    </LinearLayout>
    

    你可以试试

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       app:layout_behavilayout_widthor="@string/appbar_scrolling_view_behavior"
       tools:showIn="@layout/activity_main"
       tools:context=".MainActivity">
    
    
       <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <EditText
            android:id="@+id/et_ONE"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <Button
            android:id="@+id/button_ONE"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button"
            android:layout_weight="1"/>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="3"/>
    
    
    </LinearLayout>
    
    </RelativeLayout>
    
        3
  •  1
  •   DKV    9 年前

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    
    
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

        4
  •  1
  •   Ojas Chimane    9 年前

    试试这个

     <?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">
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="EditText"/>
    
               <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button"/>
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    
        </LinearLayout>
    
        5
  •  0
  •   Ajeet Choudhary Sagar Shah    9 年前

    使用 LinearLayout 之前 RecyclerView 并向他们提供ID(例如temp)和使用 RelativeLayout layout_below 和 ,就像这样 android:layout_below="@id/temp" (这将确保您的 回收视图 线性布局 ),现在添加您的 Button EditText 这一点 线性布局 线性布局 wrap_content 进入高度)

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:="match_parent"
        app:layout_behavilayout_widthor="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/activity_main"
        tools:context=".MainActivity">
    
    <LinearLayout
        android:id="@+id/temp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
    
    
        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>
    
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/temp" />
    
    </RelativeLayout>
    

    希望能有所帮助!!