2016-09-30 49 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" 
      />