【发布时间】:2015-06-07 23:31:41
【问题描述】:
我的场景是这样的: 我有一个线性布局,其中有一个图像视图和大约 10 个编辑文本。我希望 ImageView 是屏幕高度的一半,剩余的编辑文本占据剩余空间并在需要时滚动。
我将线性布局包裹在滚动视图中,并将权重总和 10 分配给线性布局。然后将 5 的 layout_weight 分配给 imageView,其余的则保留 wrap_content 的 layout_height。但这完全隐藏了图像视图。我应该如何获得我想要的布局?
我的 layout.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="10dp"
android:id="@+id/imageView" android:layout_gravity="center" android:background="#bcddff"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Launch Camera"
android:id="@+id/button" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:id="@+id/name" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Mobile No."
android:id="@+id/mobile" android:layout_gravity="center" android:inputType="phone"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Whatsapp No."
android:id="@+id/whatsapp" android:layout_gravity="center" android:inputType="phone"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:id="@+id/email" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Age"
android:id="@+id/age" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:id="@+id/address" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="City"
android:id="@+id/city" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="State"
android:id="@+id/state" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Gender(M/F)"
android:id="@+id/gender" android:layout_gravity="center"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Remarks"
android:id="@+id/remarks" android:layout_gravity="center"/>
</LinearLayout>
</ScrollView>
【问题讨论】: