如何调整的LinearLayout垂直中心? [英] How to align linearlayout to vertical center?

查看:152
本文介绍了如何调整的LinearLayout垂直中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我tyring对齐的LinearLayout的这显示了在PIC(skycolor境)垂直中心删除按钮的垂直中心。

所以我设置的ID比重。groupNumbers到center_vertical

但没有改变。

如何调整ID:groupNumbers到按钮的中心

 < XML版本=1.0编码=UTF-8&GT?;

< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
              机器人:方向=横向
              机器人:layout_width =match_parent
              机器人:layout_height =match_parent>

    <的LinearLayout
            机器人:ID =@ + ID / groupNumbers
            机器人:方向=横向
            机器人:重力=center_vertical
            机器人:layout_weight =0.7
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT>

        <的LinearLayout
                机器人:方向=横向
                机器人:layout_weight =1
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT>

            <的TextView
                    机器人:ID =@ + ID / txtSelected01
                    机器人:文本=00
                    机器人:TEXTSIZE =30dp
                    机器人:重力=center_horizo​​ntal
                    机器人:layout_weight =1
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT/>
        < / LinearLayout中>

        <的LinearLayout
                机器人:方向=横向
                机器人:layout_weight =1
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT>

            <的TextView
                    机器人:ID =@ + ID / txtSelected02
                    机器人:文本=00
                    机器人:TEXTSIZE =30dp
                    机器人:重力=center_horizo​​ntal
                    机器人:layout_weight =1
                    机器人:layout_width =0dp
                    机器人:layout_height =WRAP_CONTENT/>
        < / LinearLayout中>
    < / LinearLayout中>


    <按钮
            机器人:ID =@ + ID / btn_deleteNum
            机器人:文本=删除
            机器人:TEXTSIZE =20dp
            机器人:layout_weight =0.2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
 

解决方案

变化的方向和重心在

 <的LinearLayout
    机器人:ID =@ + ID / groupNumbers
    机器人:方向=横向
    机器人:重力=center_vertical
    机器人:layout_weight =0.7
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT>
 

 安卓方向=垂直
机器人:layout_gravity =center_vertical
 

您添加的方向:水平,这样的布局将包含在同一水平线上的所有元素。这不会让你得到的中心元素。

希望这有助于。

I'm tyring to align linearlayout's vertical center which shows following pic (skycolor border) to delete button's vertical center.

so I set gravity of id:groupNumbers to center_vertical.

but no changed.

How to align id:groupNumbers to buttons's center?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <LinearLayout
            android:id="@+id/groupNumbers"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:layout_weight="0.7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        <LinearLayout
                android:orientation="horizontal"
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <TextView
                    android:id="@+id/txtSelected01"
                    android:text="00"
                    android:textSize="30dp"
                    android:gravity="center_horizontal"
                    android:layout_weight="1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
        </LinearLayout>

        <LinearLayout
                android:orientation="horizontal"
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <TextView
                    android:id="@+id/txtSelected02"
                    android:text="00"
                    android:textSize="30dp"
                    android:gravity="center_horizontal"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>


    <Button
            android:id="@+id/btn_deleteNum"
            android:text="Delete"
            android:textSize="20dp"
            android:layout_weight="0.2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
</LinearLayout>

解决方案

Change orientation and gravity in

<LinearLayout
    android:id="@+id/groupNumbers"
    android:orientation="horizontal"
    android:gravity="center_vertical"
    android:layout_weight="0.7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

to

android:orientation="vertical"
android:layout_gravity="center_vertical"

You are adding orientation: horizontal, so the layout will contain all elements in single horizontal line. Which won't allow you to get the element in center.

Hope this helps.

这篇关于如何调整的LinearLayout垂直中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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