Android的相对布局对齐父权 [英] Android relative layout align parent right

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

问题描述

我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/test_ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/main_layPanelCircle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="15dp"
    android:background="@drawable/main_panel_a"
    android:orientation="vertical"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/main_imgBreachAlert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp" />

    <Button
        android:id="@+id/main_btnMap"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="@null"
        android:drawableTop="@drawable/icon_find"
        android:text="@string/main_locate"
        android:textColor="@android:color/white"
        android:textSize="10sp" />

    <LinearLayout
        android:id="@+id/main_llPanelCycleMiddle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main_btnMap"
        android:layout_centerInParent="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/main_btnLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:drawableTop="@drawable/icon_call"
            android:text="@string/main_call"
            android:textColor="@android:color/white"
            android:textSize="10sp"
            android:visibility="visible" />

        <Button
            android:id="@+id/main_btnEmergency"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:drawableTop="@drawable/icon_emergency"
            android:scaleType="center"
            android:text="@string/main_emergency"
            android:textColor="@android:color/white"
            android:textSize="9sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/main_btnRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:drawableTop="@drawable/icon_store"
            android:text="@string/main_store"
            android:textColor="@android:color/white"
            android:textSize="10sp" />
    </LinearLayout>

    <Button
        android:id="@+id/main_btnMore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main_llPanelCycleMiddle"
        android:layout_centerHorizontal="true"
        android:background="@null"
        android:drawableTop="@drawable/icon_more"
        android:text="@string/main_more"
        android:textColor="@android:color/white"
        android:textSize="10sp" />
</RelativeLayout>

</LinearLayout>

当我设置main_imgBreachAlert机器人:layout_alignParentLeft =真eveerything是OK(左图),但是当我将它设置为正确的矿井相对布局延伸(左图):

When i set main_imgBreachAlert android:layout_alignParentLeft="true" eveerything is OK (left image) but when i set it to right mine relative layout stretches (left image):

http://i.imgur.com/uDJqF0k.jpg?1

你能请告知我怎么能解决这个问题。

Could you please advise how could I fix this problem.

日Thnx

推荐答案

尝试的android:layout_centerInParent =真正的,然后取出alignParentLeft属性,如果你婉实现什么图像集中在你的布局。

Try android:layout_centerInParent="true" and remove the alignParentLeft attribute if what you wan to achieve is the image centered in your layout.

如果您只想将其调整到合适的,只要使用的android:layout_alignParentRight =真正的

If you only want to align it to the right, just use android:layout_alignParentRight="true".

<ImageView
    android:id="@+id/main_imgBreachAlert"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginRight="5dp" />

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

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