2014-10-18 28 views
1
<ImageView 
    android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/nextarrow_final" 
/> 

我要這張圖片在左側。在ImageView中將圖像置於左側,以防ImageView佔用整個屏幕的寬度?

任何幫助?

+0

機器人:重力=「左」 – Amy 2014-10-18 04:48:42

+0

放imgaeview成的LinearLayout垂直與線性佈局到左,設置ImageView的參數的集合重力相同的參數來包裝內容 – koutuk 2014-10-18 04:49:38

+0

嘗試這種機器人:scaleType =「fitStart」參考 http://stackoverflow.com/questions/655994/android-layout-alignment-issue-with-imageview – Ravin 2014-10-18 04:51:19

回答

0

嘗試:

android:layout_alignParentLeft="true" 
0

試試這個。

<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:layout_gravity="center" 
    android:orientation="vertical"> 


    <ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:src="@drawable/nextarrow_final"/> 

</LinearLayout> 

希望這有助於:)

+0

它不起作用。 – 2014-10-18 06:27:57

+0

因爲您的圖像寬度爲「fill_parent」,您是否希望圖像寬度覆蓋整個屏幕?如果沒有,然後嘗試把一些像素,例如。 android:layout_width =「80dp」,而不是使用「fill_parent」。 – 2014-10-18 06:46:19

0

你提到的寬度 「補父」。因此,它將佔用全寬,而不是在左對齊的線性佈局內爲寬度和高度「包裝內容」。我認爲它可以幫助你。

+0

我知道這一點。但我想保持寬度「fill_parent」,並在裏面,篩選出小圖像。 – 2014-10-18 06:25:53

5

@Anish米塔爾

我在這裏說明在這兩個佈局你的問題的解決方案:

1>線性佈局

這個代碼把裏面的主直線佈局

 <LinearLayout 
     android:id="@+id/learlayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="35dp" 
     android:gravity="center" > 

     <ImageView 
      android:id="@+id/img" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="0" 
      android:src="@drawable/facebook" /> 

     <View 
      android:id="@+id/view1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </LinearLayout> 

2>相對佈局

android:scaleType="fitStart" 

此代碼是多屏幕支持另外.... !!!

+0

哈哈哈。我上面所說的。我想保持寬度爲fill_parent。並且您將父寬度設置爲「wrap_content」。 – 2014-10-18 06:41:19

+0

我知道你的問題,但如果你在圖像的右側有一些空間,這個任務是完全填充 – 2014-10-18 06:58:53

+0

android:scaleType =「fitStart」效果很好〜! – JSong 2017-01-13 02:43:58

0

試試這個在您的佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" > 
<ImageView 
    android:id="@+id/image" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

在代碼中添加此:

image.setScaleType(ImageView.ScaleType.FIT_XY); 
+1

ScaleType.FIT_XY不起作用。相反ScaleType fitStart的作品。 :) – 2014-10-18 07:52:56

1

這在你的佈局嘗試。 (機器人:scaleType =「fitStart」)

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorDefaultBg"> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:scaleType="fitStart" 
      android:id="@+id/image_logo" 
      android:src="@drawable/my_logo" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="" 
      android:padding="10dp" 
      android:id="@+id/text_title" 
      android:layout_gravity="center_vertical" /> 

    </LinearLayout> 
相關問題