【发布时间】:2015-01-03 22:29:14
【问题描述】:
我正在尝试创建一个布局,该布局具有一个图像视图和另一个包含 2 个文本视图的 LinearLayout。我希望 imageView 占据总布局高度的 60% 以及由 textViews 的布局获取的剩余空间。然而问题是图像视图的高度没有成为总高度的 60%。它随着图像的尺寸而变化。我一直无法弄清楚这种行为背后的原因。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myView”
android:layout_width="@dimen/my_width"
android:layout_height="match_parent"
android:layout_marginBottom="6dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0"
android:orientation="vertical" >
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:layout_weight=“0.6”
android:src="@drawable/ic_launcher"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.40”
android:layout_below="@+id/imageLayout"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="7dp"
android:maxLines="1"
android:paddingLeft="@dimen/my_padding"
android:paddingRight="@dimen/my_padding"
android:text=“hello “world/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:paddingLeft="16dp"
android:text=“ty”/>
<View
android:layout_width="0dp"
android:layout_height=“match_parent"
android:layout_weight="1"
></View>
<Button
android:layout_width="@dimen/but_width"
android:layout_height="@dimen/but_height"
android:layout_gravity="right|bottom"
android:text=“button”
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
最好的问候
【问题讨论】:
标签: android android-linearlayout android-layout-weight