2016-01-07 22 views
-4

enter image description here
我怎样才能把TextView完全ImageView下面? 我写下面的代码,但它把TextView以下的图像保证金, 我也尝试不同的scaleTypeImageView的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="match_parent" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/list_row_logo" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="0dp" 
      android:padding="0dp" 
      android:src="@drawable/nature_bg" /> 
    </FrameLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="hello" /> 
</LinearLayout> 
+4

加上'机器人:adjustViewBounds = “真”'在ImageView的XML。 –

+0

@mohammad你可以发布或'nature_bg'图片吗?它可能有空白空间 – user1140237

+0

user114 ...图像没有空白,我敢肯定。 – Mohammad

回答

0

为ImageView添加android:adjustViewBounds="true"属性。将其设置为true将调整其边界以保留其可绘制的高宽比。

<ImageView 
     android:id="@+id/list_row_logo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="0dp" 
     android:padding="0dp" 
     android:adjustViewBounds="true" 
     android:src="@drawable/beekeeper_logo" /> 
0

您可以使用RelativeLayout的替代,并把这样的图像下面的TextView:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/list_row_logo" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="0dp" 
      android:padding="0dp" 
      android:src="@drawable/nature_bg" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="hello" 
      android:layout_below="@id/list_row_logo"/> 

</RelativeLayout>