2013-04-20 26 views
3

我有要在第二行中的ImageView的伸展如果可能的話,以適應該行視圖此佈局XML和第一行中的TextView的粘貼在屏幕的左側和我會在中心需要它。 ImageView正在充滿從相機拍攝的圖像,任何幫助表示讚賞。圖像視圖伸展配合錶行寬度

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

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_gravity="center" 
    android:layout_weight="1" 
    android:stretchColumns="*" > 

    <TableRow android:id="@+id/tableRow1" > 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:layout_gravity="center" 
       android:text="Set Your Personal Information Here" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
     </LinearLayout> 
    </TableRow> 

    <TableRow android:id="@+id/tableRow2" > 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </LinearLayout> 
    </TableRow> 

    <TableRow android:id="@+id/tableRow3" > 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <QuickContactBadge 
       android:id="@+id/quickContactBadge1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Name" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textView3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Gender" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 

       <TextView 
        android:id="@+id/textView4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Credits" 
        android:textAppearance="?android:attr/textAppearanceMedium" /> 
      </LinearLayout> 
     </LinearLayout> 
    </TableRow> 
</TableLayout> 

+0

在帶有Imageview的Linearlayout上,將方向設置爲水平並移除佈局權重,並在Imageview上添加scaleType FIT_XY,看看是否有這個技巧。 – 2013-04-20 01:21:02

+0

'FIT_XY'不是一個有效的參數,雖然 – kabuto178 2013-04-20 01:57:46

+1

抱歉它的fitXY試試。 – 2013-04-20 02:06:13

回答

13

由於@Brosa在評論說,使用android:scaleType="fitXY"屬性。

g雖然你必須找到自己的解決方案,我寫這個答案寫關於未來幫助android:scaleType不同選項的簡要說明。

有這attreibute幾個選項。他們是

  1. 矩陣
  2. fitXY
  3. fitStart
  4. fitCenter
  5. fitEnd
  6. 中心
  7. centerCrop
  8. centerInside

下面是繪製時使用圖像矩陣那些從doc

1.矩陣
規模小的描述。

2. fitXY
量表中X和Y獨立圖像,使得SRC完全匹配DST。這可能會改變src的寬高比。

3. fitStart
量表通過計算比例,將保持原來的SRC的縱橫比,但也將確保完全的src適合內部dst中的圖像。至少有一個軸(X或Y)將完全適合。 START將結果與dst的左邊緣和頂邊緣對齊。

4. fitCenter
量表通過計算比例,將保持原來的SRC的縱橫比,但也將確保完全的src適合內部dst中的圖像。至少有一個軸(X或Y)將完全適合。結果集中在dst中。

5. fitEnd
量表通過計算比例,將保持原來的SRC寬高比的圖像,但也將確保SRC內部DST完全配合。至少有一個軸(X或Y)將完全適合。 END將結果與dst的右邊緣和底邊緣對齊。

6.中心
中心在視圖中的圖像,但是不執行任何縮放。

7. centerCrop
縮放圖像均勻(保持圖像的縱橫比),以使圖像的兩個尺寸(寬度和高度)會比視圖的相應尺寸等於或大於(負填充)。

8. centerInside
縮放圖像均勻(保持圖像的縱橫比),以使圖像的兩個尺寸(寬度和高度)會比視圖的相應尺寸等於或小於(減去填充)。

+0

感謝您的分解,我只是在尋找其他枚舉類型以及 – kabuto178 2013-04-20 03:50:27

+0

它的工程很棒!謝謝! – 2013-12-20 01:03:41