【发布时间】:2014-12-04 12:58:10
【问题描述】:
我目前正在尝试组合一个由几个输入控件和一个列表视图组成的布局,并使用 layout_weight 在 Android Studio 预览中让它看起来像我想要的那样。但是,在实际设备上,布局看起来完全不同。
我对 Android 还很陌生,之前在他们的布局上遇到过一些问题,所以我可能遗漏了一些东西。但是,我一直在阅读不同类型的布局,尤其是 layout_weight,到目前为止我发现的所有内容都让我认为结果看起来像 Android Studio 的预览版。在这种情况下,我可以轻松地适应另一种布局,但我更愿意真正了解问题所在,因为我将来可能会再次遇到同样的问题。
以下是我的布局代码和比较图像。 非常感谢任何想法或提示。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/input_title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="@string/title"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:id="@+id/input_submit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:text="@string/input_submit"/>
<Button
android:id="@+id/input_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/input_submit"
android:text="@string/input_date"/>
<EditText
android:id="@+id/input_amount"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/input_date"
android:layout_toLeftOf="@id/input_date"
android:hint="@string/amount"
android:inputType="numberDecimal"/>
</RelativeLayout>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"/>
</LinearLayout>
Android Studio 预览版:http://i.stack.imgur.com/4bWM6.png
设备上的实际布局:http://i.stack.imgur.com/MJbOX.png
【问题讨论】:
标签: android android-layout android-linearlayout android-layout-weight