2013-07-12 26 views
1
越来越

安卓重力选项不能与ImageView的

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight=".35" > 

    <ImageView 
     android:id="@+id/txt_loginpage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/yellow" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight=".65" > 

    <Button 
     android:id="@+id/edtCardnum" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/request" /> 
</LinearLayout> 

我不能让android:gravity选项与Imageview,但我可以Textview得到它。

在我的代码中是否有任何错误。

如果我将此更改为Textview,则android:gravity选项正在工作,但不会与Imageview

<ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/txt_loginpage" 
     android:background="@drawable/yellow" /> 

回答

1

安卓重力选项用于设置支架视图的内容设置在里面持有特定位置view.It的工作类似于一个Word文档的对齐属性page.when您使用的ImageView没有内容在里面,它只是位图,并设置位图的不同位置在特定位置,您可以使用scaletype选项。否则,您必须使用重力选项到图像视图的父级。

如果您希望获得相同的效果,请将重力放在父线性布局上。