【发布时间】:2013-06-29 20:49:06
【问题描述】:
我不明白 ImageView 大小如何在定义了权重的相对布局上起作用
这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CameraActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="76" >
<ImageView
android:id="@+id/imagePreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/photo_placeholder" />
<Button
android:id="@+id/timeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="onClick"
android:text="Button" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="24" >
<ImageButton
android:id="@+id/mainButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#0fff"
android:src="@drawable/cam_main_btn_normal" />
<ImageButton
android:id="@+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="22dp"
android:background="#0fff"
android:src="@drawable/gs_05_check_normal" />
<ImageButton
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:background="#0fff"
android:src="@drawable/cam_cancel" />
</RelativeLayout>
</LinearLayout>
我明白了 但是如果我删除图像,它会按照我的预期正确显示尺寸
所以问题是,我应该怎么做才能让 imageView 在相对布局的权重方面占据全部空间?
我尝试将 imageView 的 android:layout_width, android:layout_height 更改为 wrap_content (没有意义,但只是检查)它不起作用。 我尝试了使用和不使用 scaleType,并且不同的值不会改变。
我猜 ImageView 需要一些技巧/魔法?
-- 编辑-- 我期望图像将在第二个屏幕截图中采用蓝色突出显示的大小:) - 编辑 - 我想要达到的目标:
【问题讨论】:
-
android:weightSum=100 在父 LinearLayout 上?
-
简单的View也存在这个问题
-
@DavidOlsson 不幸的是我已经尝试过了,但它不起作用。
-
@gigigan 你能给我 photo_placeholder 和 gs_05_check_normal 图像吗?我想测试一下。我没有它测试过似乎都是正确的。
-
我明白了。我不知道这是否会有所作为,但您应该使用
dp而不是px来代替height
标签: android android-layout android-imageview