<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>
我无法通过 Imageview
获得 android:gravity
选项,但我可以通过 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" />
最佳答案
android:gravity 选项用于设置 holder view 的内容以设置在 holder view 内的特定位置。它的工作方式与 word 文档页面的对齐属性相同。当您使用 imageview 时,它里面没有内容,它只要有位图并在特定位置设置该位图的不同位置,您可以使用 scaletype 选项。否则,您必须对 imageview 的父级使用 gravity 选项。
如果您想要相同的效果,请将引力放在父线性布局上。
关于android:gravity 选项不支持 Imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17616009/