[英]ImageView in LinearLayout
這種布局有兩個問題:
<?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="130dp"
android:orientation="horizontal"
android:background="@null">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/image1"
android:id="@+id/image1"
android:scaleType="centerCrop"
android:background="@drawable/card_background"
android:layout_weight=".5"
/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/image2"
android:id="@+id/image2"
android:scaleType="centerCrop"
android:background="@drawable/card_background"
android:layout_weight=".5"
/>
</LinearLayout>
當我在ImageViews中放置不同的Images時,發生了這種情況:
此代碼有效,為什么? 我真的不知道。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="130dp"
android:background="@null"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="130dp"
android:id="@+id/image2"
android:scaleType="centerCrop"
android:src="@drawable/offer_mix_small_1"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="@color/secondary_text_color"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="130dp"
android:id="@+id/image1"
android:scaleType="centerCrop"
android:src="@drawable/offer_land"
/>
</RelativeLayout>
</LinearLayout>
您忘記在根布局中添加weightsum,因此在根布局中添加此行。
android:weightSum="1"
就像加上重量和之后
<?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="130dp"
android:weightSum="1"
android:orientation="horizontal"
android:background="@null">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/image1"
android:id="@+id/image1"
android:scaleType="centerCrop"
android:background="@drawable/card_background"
android:layout_weight=".5"
/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="@drawable/image2"
android:id="@+id/image2"
android:scaleType="centerCrop"
android:background="@drawable/card_background"
android:layout_weight=".5"
/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.