3
的整个宽度

我的XML如下的Android ImageView的扩大屏幕

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#FFFFFF"> 

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TableRow android:layout_weight="1" android:gravity="center"> 
     <ImageView android:layout_height="200dp" 
      android:layout_width = "wrap_content" 
      android:src="@drawable/saltnpepper"     
      android:scaleType="centerInside" /> 
    </TableRow> 

    <TableRow android:layout_weight="3" > 
    <ListView android:id="@+id/list1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
    > 

    </ListView> 
</TableRow> 
<TableRow android:layout_weight="1" android:gravity="center"> 
    <ImageView android:layout_height="100dp" 
      android:layout_width = "wrap_content" 
      android:src="@drawable/halal" 
      android:scaleType="centerInside"/> 
</TableRow> 
</TableLayout> 

我的屏幕是目前这样的:

enter image description here

我想Saltnpepper图像跨越扩大屏幕宽度,我试图设置ImageViewlayout_height0dp,但图像消失。我也试过它作为match_parentlayout_width,但没有奏效

另外,我想添加一些缘至ListView但整个table_layout移动如果我添加marginRightmarginLeftListView元素。

+0

的android:layout_width = “match_parent” 运作的?和列表视图,尝试用paddingLeft和paddingRight – X3Btel

+0

+0

感谢Adeel它确实有效!只有现在形象被拉伸可能是我应该把它放在背景 – Samra

回答

0

所以我尝试了所有的解决方案,但有一点工作,其他的事情了扭曲。我尝试了Adeel Turk的解决方案fitXY,它立即让我的图像适合屏幕,但图像太有弹性,所以现在我已经把我的图像作为背景,它给了我很好的结果。

这里是我的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 

<TableLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent"  
android:background="@drawable/saltnpepper"> 
<TableRow android:layout_weight="1" android:gravity="center"> 
    <TextView android:layout_height="200dp"/> 
</TableRow> 

<TableRow android:layout_weight="4" > 
<ListView android:id="@+id/list1" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
> 

</ListView> 
</TableRow> 
<TableRow android:layout_weight="1" android:gravity="center"> 
<ImageView android:layout_height="100dp" 
     android:layout_width = "wrap_content" 
     android:src="@drawable/halal" 
     android:scaleType="centerInside"/> 
</TableRow> 
</TableLayout></LinearLayout> 

enter image description here

1

在您的ImageView上设置版面宽度为match_parent。此外,请将ImageView的背景颜色设置为某种东西,以便您可以看到它实际占用了多少空间。从那里,你想使用scaleType塑造(裁剪/适合/等)图像到ImageView的空间。

0

将图像视图宽度设置为match_parent并将高度设置为wrap_content,以保持您可以使用adjustViewBounds设置为TRUE的纵横比。

0

下面的代码使用....试试吧...

android:layout_width = "match_parent" 
android:paddingLeft="10dp" 
android:paddingRight="10dp" 
android:paddingTop="10dp" 
android:adjustViewBounds="true" 

结局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <TableRow android:layout_weight="1" android:gravity="center"> 
      <ImageView android:layout_height="200dp" 
       android:layout_width = "match_parent" 
       android:src="@drawable/saltnpepper" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
        android:paddingTop="10dp" 
       android:adjustViewBounds="true" 
       android:scaleType="centerInside" /> 
     </TableRow> 

     <TableRow android:layout_weight="3" > 
     <ListView android:id="@+id/list1" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
     > 

     </ListView> 
    </TableRow> 
    <TableRow android:layout_weight="1" android:gravity="center"> 
     <ImageView android:layout_height="100dp" 
       android:layout_width = "wrap_content" 
       android:src="@drawable/halal" 
       android:scaleType="centerInside"/> 
    </TableRow> 
    </TableLayout> 
+0

nope图像didnot扩大 – Samra