如何使用6个按钮为中心的LinearLayout上纵向和横向的中心? [英] How to center linearlayout with 6 buttons on the center on portrait and landscape orientation?

查看:104
本文介绍了如何使用6个按钮为中心的LinearLayout上纵向和横向的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现什么:中心布局与两个方向

What I want to achieve: Center layout with both orientation.

    <ScrollView
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#fffffce0">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#fffffce0"
    android:weightSum="1">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="121dp"
        android:background="#fffffce0"
        android:layout_marginTop="42dp"
        android:id="@+id/linearLayout"
        android:gravity="center_horizontal"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <Button
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/button9"
            android:background="@drawable/custom_button_square"
            android:text="@string/a_d"
            android:textColor="#ffff"
            android:textSize="35sp"
            android:onClick="goToAd"/>

        <Button
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/button10"
            android:background="@drawable/custom_button_square"
            android:text="@string/e_h"
            android:textColor="#ffff"
            android:textSize="35sp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:layout_below="@+id/linearLayout"
        android:layout_centerHorizontal="true"
        android:gravity="center_horizontal"
        android:background="#fffffce0"
        android:id="@+id/linearLayout2">

        <Button
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/button11"
            android:background="@drawable/custom_button_square"
            android:text="@string/i_l"
            android:textColor="#ffff"
            android:textSize="35sp" />

        <Button
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/button12"
            android:background="@drawable/custom_button_square"
            android:text="@string/m_p"
            android:textColor="#ffff"
            android:textSize="35sp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:layout_below="@+id/linearLayout2"
        android:layout_centerHorizontal="true"
        android:background="#fffffce0"
        android:gravity="center_horizontal">

        <Button
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/button13"
            android:background="@drawable/custom_button_square"
            android:text="@string/m_p"
            android:textColor="#ffff"
            android:textSize="35sp" />

        <Button
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:id="@+id/button14"
            android:background="@drawable/custom_button_square"
            android:text="@string/q_t"
            android:textColor="#ffff"
            android:textSize="35sp" />
    </LinearLayout>

</RelativeLayout>

问题:
一切正常,直到那一刻我被测试我的平板电脑应用有更大的屏幕。当方向是横向,everyting是好的,但是当我旋转屏幕,那么它看起来像:
http://zapodaj.net/b2780f7e637ab.png.html

我试图把我的重力我Llayout为中心,但它没有工作。

I tried to set my gravity i Llayout to center, but it didnt work.

推荐答案

嘛!喜欢这个。试试这个..

Well ! Like This. Try This..

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fffffce0" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fffffce0"
    android:gravity="center"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:weightSum="1" >

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="121dp"
        android:layout_marginTop="42dp"
        android:background="#fffffce0"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button9"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher"
            android:onClick="goToAd"
            android:text="a_d"
            android:textColor="#ffff"
            android:textSize="35sp" />

        <Button
            android:id="@+id/button10"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher"
            android:text="e_h"
            android:textColor="#ffff"
            android:textSize="35sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="#fffffce0"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button11"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher"
            android:text="i_l"
            android:textColor="#ffff"
            android:textSize="35sp" />

        <Button
            android:id="@+id/button12"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher"
            android:text="m_p"
            android:textColor="#ffff"
            android:textSize="35sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="#fffffce0"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button13"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher"
            android:text="m_p"
            android:textColor="#ffff"
            android:textSize="35sp" />

        <Button
            android:id="@+id/button14"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/ic_launcher"
            android:text="q_t"
            android:textColor="#ffff"
            android:textSize="35sp" />
    </LinearLayout>
</LinearLayout>

这篇关于如何使用6个按钮为中心的LinearLayout上纵向和横向的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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