2016-09-30 73 views
1

我一直在爲這一整天的事情而苦苦掙扎。我想在我的LinearLayout中使用3個圖像視圖。正如你所看到的,這個比例是不正確的。我所有的圖標都有24x24像素的大小。在我的ImageViews裏面試驗過不同的房產。LinearLayout中的ImageViews - 搞亂了規模

這裏是我的XML代碼:

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="45dp" 
      android:orientation="horizontal"> 

      <ImageView 
       android:id="@+id/tList" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:scaleType="fitXY" 
       android:background="@drawable/ic_home_black_24px" /> 

      <ImageView 
       android:id="@+id/ist" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:scaleType="fitXY" 
       android:background="@drawable/ic_help_black_24px" 
       /> 

      <ImageView 
       android:id="@+id/ations" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:scaleType="fitXY" 
       android:background="@drawable/ic_settings_black_24px" 
       /> 
</LinearLayout> 

prev

+0

您是否嘗試過改變每個'ImageView'的'「FILL_PARENT」'屬性?填充父項將強制'ImageView'適合父項的寬度和高度。 – pamobo0609

+0

也許最好的辦法是嘗試在寬度和高度上使用'wrap_content'屬性,或者使用'dp'相當於'24px' – pamobo0609

+0

是的,我首先將它設置爲wrap_content,但這並沒有讓它變得更好。我甚至嘗試將layout_width和layout_height設置爲24dp。仍然搞砸了規模... –

回答

1

我粘貼您的佈局文件中的代碼在我Android Studio,一個似乎weightscaleType屬性搞亂你的看法。這是我聲明瞭一個24×24 ImageView

<ImageView 
    android:id="@+id/ations" 
    android:layout_width="24dp" 
    android:layout_height="24dp" 
    android:background="@drawable/your_drawable" 
    /> 

您可以查看完整的DOC約weighthere,但什麼是基本的意思是,如果你把weight幾個屬性下LinearLayout,您要添加在屏幕顯示時增長的優先級。由於3 ImageViews有1作爲weight,他們增長具有相同的優先級,並且由於也調用fill_parent,他們將強制適應父級佈局參數,看起來奇怪。

0

更改所有的ImageView寬度爲「0dp」並更換背景SRC是這樣的:

<ImageView 
      android:id="@+id/ations" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:scaleType="fitXY" 
      android:src="@drawable/ic_settings_black_24px" 
      />