作爲一個較大的項目的一部分,我試圖創建一個自定義圖像庫,它將保存來自網絡的圖像。我無法控制它們的大小和佈局(順序,總數[最多十個],每行數[最多三個])由我正在使用的API定義。我使用嵌套LinearLayouts以編程方式構建鬆散電網但這是概念的XML證明...Android layout_height包裝最小的孩子
<?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:orientation="vertical"
android:divider="@drawable/photoset_vert_divider"
android:showDividers="middle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:divider="@drawable/photoset_horz_divider"
android:showDividers="middle">
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:src="@drawable/tall" />
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:src="@drawable/tall" />
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:src="@drawable/wide" />
</LinearLayout>
</LinearLayout>
這就是我正在尋找的60%,並讓我
...但這是我的目標:
我要的是一個android:layout_height="wrap_smallest_content"
種將所有ImageView縮放到正確尺寸的東西,然後將它們全部裁剪以匹配「最短」的孩子。
嘗試將此android:scaleType =「centerCrop」替換爲android:scaleType =「fitXY」 .... –