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