【发布时间】:2014-10-21 06:49:30
【问题描述】:
我有一个 LinearLayout,它是 ScrollView 的直接子级,有两个子级。第一个孩子几乎可以是任何高度(它是一个图像),但第二个孩子的内容会比视口的高度大得多。我尝试使用 layout_weight 来实现这一点,但这只会导致图像被设置为 1dp 之类的东西,而第二个孩子占据了其余部分,因为权重只分配给剩余空间。
如何强制图像占用至少 40% 的屏幕空间?
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:src="@drawable/my_image" />
<LinearLayout
android:id="@+id/prediction_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@android:color/white"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[really long text]" />
</LinearLayout>
</LinearLayout>
</ScrollView>
【问题讨论】:
标签: android android-layout android-linearlayout parent-child