2017-01-21 136 views
0

我有两个问题,这个布局:的ImageView中的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,发生这种情况:

  • 的ImageViews高度大于130dp更大,但是我把身高为(match_parent),父身高为130dp。
  • ImageViews宽度不一样,但是两个ImageView的重量相同,但较大的宽度比另一个要宽。
+0

你没有给一个weight_sum父布局 –

+0

我做了之后,它仍然是你的意思是相同的 – Maysara

+0

映像不在大小或这些意见相同大小不一样?您可以在imageViews中使用'scaletype = fitxy'来使图像适合其边界 –

回答

0

此代码有效,为什么? 我真的不知道。

<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> 
0

您忘记在根布局中添加权重,因此将此行添加到根布局中。

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> 
+0

不,它是相同的 – Maysara

相关问题