2014-10-18 41 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> 
相关问题