Android的布局右对齐 [英] Android Layout Right Align

查看:214
本文介绍了Android的布局右对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制定了以下布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1">


        <WebView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/webview" android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <LinearLayout android:orientation="horizontal"  android:layout_width="fill_parent" android:layout_height="fill_parent"  android:layout_weight="13">
        <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
                    <ImageButton android:background="@null" android:id="@+id/back" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/back" android:padding="10dip" />
            </LinearLayout>

            <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
                <ImageButton android:background="@null" android:id="@+id/forward" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/forward" android:padding="10dip" />
            </LinearLayout>

        </LinearLayout>

        <RelativeLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="fill_parent"    android:layout_weight="1" >
                <ImageButton android:background="@null" android:id="@+id/special"   android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/barcode" android:padding="10dip" android:layout_gravity="right"/>
        </RelativeLayout>




    </LinearLayout>


</LinearLayout>

有关这个问题的目的,我只关注布局的下半部分。现在,它包含3个imagebuttons。第2,我想紧挨着对方左对齐。第三个,我想被对准到右侧。

For the purpose of this question, I am only concerned about the lower half of the layout. Right now it contains 3 imagebuttons. The first 2, I want right next to each other left aligned. The third one, I want to be aligned to the right side.

由于是第2按钮,我想他们是,但第三个是stubbernly住左对齐。我将如何作出正确对齐。

As is, the first 2 buttons are where I want them to be, but the 3rd is stubbernly staying left-aligned. How would I make it right aligned.

推荐答案

布局是非常低效和臃肿。你并不需要很多的LinearLayout 秒。其实你不需要任何的LinearLayout 的。

The layout is extremely inefficient and bloated. You don't need that many LinearLayouts. In fact you don't need any LinearLayout at all.

使用只有一个 RelativeLayout的。就像这一点。

Use only one RelativeLayout. Like this.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageButton android:background="@null"
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/back"
        android:padding="10dip"
        android:layout_alignParentLeft="true"/>
    <ImageButton android:background="@null"
        android:id="@+id/forward"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/forward"
        android:padding="10dip"
        android:layout_toRightOf="@id/back"/>
    <ImageButton android:background="@null"
        android:id="@+id/special"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/barcode"
        android:padding="10dip"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

这篇关于Android的布局右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆