【发布时间】:2017-02-02 03:32:39
【问题描述】:
我不知道为什么会这样。我敢打赌这很简单,但我不知道为什么。我有一个评论活动,其中一个相对布局作为父级,一个 RecyclerView 以及一个线性布局(有 2 个子级:一个编辑文本和一个提交按钮)作为子级。我的 layout.xml 如下
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_comment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.erik.appname.CommentActivity">
<android.support.v7.widget.RecyclerView
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="470dp"
android:id="@+id/posted_comments">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:id="@+id/write_comment"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/posted_comments"
android:layout_alignParentStart="true">
<EditText
android:layout_alignParentBottom="true"
android:paddingLeft="10dp"
android:layout_width="0dp"
android:layout_weight="8"
android:background="@drawable/input_outline2"
android:layout_height="match_parent"
android:inputType="textPersonName|textMultiLine"
android:text=""
android:gravity="left|center"
android:hint="Comment..."
android:textSize="20dp"
android:maxLength="100"
android:id="@+id/current_comment" />
<ImageButton
android:src="@drawable/submit"
android:scaleType="fitCenter"
android:padding="5dp"
android:background="@drawable/input_outline2"
android:layout_alignParentBottom="true"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/submit"
android:layout_toEndOf="@+id/current_comment"
/>
</LinearLayout>
这是我从预览中得到的(我希望它看起来像) preview
虽然这是来自实际设备的屏幕截图real device
为什么recyclerview下方的edittext和按钮会这样?
我尝试了很多事情,例如将所有内容包装在线性布局中,将 RelativeLayout 包装在线性布局中,将包含编辑文本和按钮的线性布局包装在另一个中,并尝试将它们堆叠起来并使用 layout_weight 来确定比例。 .. 似乎无法找出正确的方法。
非常感谢您的帮助!
【问题讨论】:
标签: xml android-layout android-linearlayout android-relativelayout xml-layout