1

<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

我的代码有什么问题吗?

如果我将其更改为Textviewthenandroid:gravity选项正在工作,但不适用于Imageview.

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

1 回答 1

1

android:gravity 选项用于设置持有人视图的内容设置在持有人视图内的特定位置。它的工作方式与 word 文档页面的对齐属性相同。当您使用 imageview 时,其中没有内容,它只有位图并在特定位置设置该位图的不同位置,您可以使用 scaletype 选项。否则,您必须对图像视图的父级使用重力选项。

如果您想要相同的效果,请将重力放在父线性布局上。

于 2013-07-12T13:38:33.193 回答