我有一个ListView,它在relativeLayout中定义了自定义项,其中包括一个带有android:layout_width="match_parent"和android:layout_height="wrap_content"的imageView,以及一个可作为源绘制的自定义向量,其原理图如下所示:
+-------------------------------------------+
+ solid area | some picture +
+-------------------------------------------+问题是,当我转向景观模式时,图像会被缩放(以获得父级的宽度),但是保持高宽比时,高度也会增加。
理想情况下,我希望定义一个内容嵌入(正如我从iOS中知道的那样),以便上面的实体区域被拉伸以匹配新的宽度,并且“一些图片”区域保持在相同的高宽比。总而言之,缩放将发生,这样图像的高度(以及整个listView项的高度)将保持不变。
发布于 2017-01-16 16:41:15
您可以通过使用布局权重在子宽度中的LinearLayout来使实体区域拉伸。要使此工作,您应该为ImageView分配一个固定的宽度。
此外,adjustViewBounds属性在ImageView上将有助于保持正确的高宽比。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal">
<!-- this can be any view or view group, the layout params are the important part-->
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
...
/>
<!-- set this to an absolute width that will be the same for portrait & landscape -->
<ImageView
android:layout_width="240dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
...
/>
</LinearLayout>https://stackoverflow.com/questions/41415451
复制相似问题