2013-05-05 173 views
14

這裏我的佈局文件:的Android ImageView的填充屏幕寬度

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:background="#000" 
tools:context=".CproductDetails" > 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/shape_bg" 
     > 

     <ImageView 
      android:id="@+id/product_image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_tweet_placeholder_photo_dark_error" 
      android:scaleType="center" /> 

     <TextView 
      android:id="@+id/product_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textColor="#95ab56" 
      android:textSize="20sp" 
      android:layout_marginTop="7dip" /> 

     <TextView 
      android:id="@+id/product_price" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="20sp" 
      android:textColor="#efeeea" /> 

     <TextView 
      android:id="@+id/product_commerce" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="20sp" /> 

     <TextView 
      android:id="@+id/product_city" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="15sp" 
      android:layout_marginTop="10dip" 
      android:layout_marginBottom="10dip" /> 

     <TextView 
      android:id="@+id/product_township" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="15sp" 
      android:visibility="gone" 
      android:layout_marginBottom="10dip" 
      android:drawableLeft="@drawable/location_place" 
      android:drawablePadding="7dip" /> 

     <TextView 
      android:id="@+id/product_website" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:autoLink="web" 
      android:textSize="15sp" 
      android:drawableLeft="@drawable/location_web_site" 
      android:drawablePadding="7dip" 
      android:visibility="gone" /> 

     <TextView 
      android:id="@+id/product_tel" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:textSize="20sp" 
      android:drawableLeft="@drawable/device_access_call" 
      android:drawablePadding="7dip" 
      android:visibility="gone" /> 

    </LinearLayout> 

在手機中的結果:

enter image description here

,結果在7英寸平板電腦:

enter image description here

我想使圖像在平板電腦中也能滿足屏幕寬度。像Twitter的應用程序,例如:

enter image description here

enter image description here

+0

你的答案將取決於你的佈局,所以你爲什麼不發佈整個XML佈局文件? – MarsAtomic 2013-05-05 01:26:43

+0

android:layout_height =「fill_parent」 – Raghunandan 2013-05-05 01:30:59

+0

@MarsAtomic done – tsil 2013-05-05 01:32:55

回答

8

謝謝大家,但你的答案都不能解決我的問題。最後我用了Maurycy Wojtowicz的ScaleImageView課。

此視圖將自動確定的寬度或高度,通過確定如果高度或寬度被設置,並且根據圖像標註

+0

網站關閉了,請更新 – fersarr 2014-03-12 06:23:26

+0

@fersarr完成! – tsil 2014-03-13 10:40:10

+0

該類手動將centerInside或centerCrop縮放添加到圖像。對於這個問題和這個問題的10個重複部分,這是一個臃腫的版本,不需要無關的類。 – LoungeKatt 2017-04-15 16:34:51

5

使用android:scaleType="fitXY"

這將獨立地縮放X和Y中的圖像,以便src完全匹配dst。這 可能會更改src的寬高比。

+2

這對於大多數照片來說都沒什麼用處,因爲長寬比很關鍵 – lilbyrdie 2015-08-03 18:28:49

40

聽起來像你想在你的ImageView上使用android:scaleType="fitCenter"android:adjustViewBounds="true"

-2

機器人縮放其他尺寸:scaleType =「fitXY」。去爲它

+0

fitXY將採用完整的x軸和y軸作爲我們描述的佈局高度 – 2016-06-16 18:17:26