首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Android水平线性布局中右对齐小工具?

如何在Android水平线性布局中右对齐小工具?
EN

Stack Overflow用户
提问于 2011-08-09 15:30:35
回答 16查看 239.5K关注 0票数 232

这是我正在使用的代码,它不工作:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="horizontal">

    <TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:gravity="right">
    </TextView>

</LinearLayout>
EN

回答 16

Stack Overflow用户

发布于 2013-02-04 06:08:16

尝试在您想要正确看到的元素之前的水平LinearLayout中添加空的View,例如:

代码语言:javascript
复制
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />                

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
票数 462
EN

Stack Overflow用户

发布于 2015-03-23 16:45:31

设置视图的layout_weight="1"就可以了。

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" />

<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

票数 26
EN

Stack Overflow用户

发布于 2011-08-09 15:40:28

android:gravity="right"添加到LinearLayout。假设TextView具有layout_width="wrap_content"

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6992804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档