gpt4 book ai didi

android - 如何在 Android 中将 View 对齐到屏幕右侧?

转载 作者:行者123 更新时间:2023-11-29 14:19:38 25 4
gpt4 key购买 nike

如何在 Android 中将 View 对齐到屏幕右侧?我用过这个但没有用请帮忙?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/widget0"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FFFFFF" android:paddingLeft="10px" android:paddingTop="10px"
android:paddingBottom="10px" android:paddingRight="10px">

<LinearLayout android:id="@+id/heading" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">

<ImageView android:id="@+id/widget30" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/logo_cpw">
</ImageView>

<EditText android:id="@+id/widget28" android:layout_width="134px"
android:layout_height="35px" android:text="EditText"
android:textSize="18sp" android:background="@drawable/rounded_edit_text_effects"
android:gravity="right" android:layout_alignParentRight="true" android:paddingRight="-10px">
</EditText>

</LinearLayout>

</RelativeLayout>

我使用了 absoluteLayout 而不是 relativelayout,但这也不起作用。请帮忙?

最佳答案

您可以在 View 上使用 android:layout_gravity 属性 - android:gravity 仅用于内容。

但我真的推荐使用 RelativeLayout,因为它通常可以立即解决大部分问题。事实上,您已经定义了一个属性 android:layout_alignParentRight="true",它仅在 RelativeLayout 中可用。

编辑:哦,不要在任何布局中使用 px - 请改用与密度无关的像素 (dp)!你真的应该阅读 User Interface chapter来自文档。

关于android - 如何在 Android 中将 View 对齐到屏幕右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4459061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com