2013-04-11 83 views
0

我有什么:ScrollView,里面 LinearLayoutImageView的宽度不匹配父

orientation="vertical", layout_width="match_parent", layout_height="wrap_content"),

里面

ImageView

layout_width="match_parent", layout_height="wrap_content")和

TextView

我想要什么:ImageView应保持宽高比和数学父宽度,和文本下面ImageView

我用的ImageView params不同的充组合:adjustViewBounds true/false和所有scaleType,但我不能得到我想要的:

  1. 如果我使用scaleType centerCrop - 顶部和底部的一部分,如果图像裁剪。
  2. 如果我使用scaleType中心 - 在空白处左右
  3. 如果我使用scaleType fitXY - 图像不保持宽高比

所以我不能使图像更加的高度,我怎么能修理它?

+0

难道你真的发表您的布局XML,也许屏幕,显示你得到它应该是什么样子?阅读代码比通过描述获得代码要容易得多... – WarrenFaith 2013-04-11 10:00:37

+0

如果图像小于父级,该怎么办?应该扩大规模吗?这会扭曲图像。 – 2013-04-11 10:01:27

+1

为您的ImageView尝试'scaleType =“fitCenter”' – 2013-04-11 10:04:19

回答

0

试试这个:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ll_main" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 
<ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:id="@+id/iv" 
     android:background="#f0f" 
     /> 
<TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Always work!!" 
      android:gravity="center" 
      android:textSize="26sp" 
      /> 
</LinearLayout> 
</ScrollView> 

注:如果scaleType没有帮助,尝试使用android:background=""代替android:src=""

enter image description here

相关问题