簡體   English   中英

Android對齊布局中心

[英]Android align layout center

我試圖在ActionBar和Bottom布局之間使用LOGO和TEXT對齊中心。 這樣

我嘗試這樣做,但它不能正常工作。 它使用scree中心的徽標進行布局。 它看起來像這樣

有誰知道misteke在哪里? 我的代碼:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

//MainLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="text" >

//LOGO Layout
<RelativeLayout
    android:id="@+id/relativeLayout0"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:gravity="center_vertical|center_horizontal|center" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/mainlogo_height"
    android:src="@drawable/gerb_big" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="17dp"
    android:gravity="center"
    android:text="text"
    android:textColor="#900000"
    android:textSize="@dimen/OA_size" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:text="text"
    android:textColor="#900000"
    android:textSize="@dimen/NU_size" />

</RelativeLayout>

//Bottom Layout
<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="false"
    android:layout_centerVertical="true"
    android:gravity="bottom|center_horizontal|center" >

    <ImageButton
        android:id="@+id/home"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="#ffffff"
        android:onClick="home_Click"
        android:scaleType="fitXY"
        android:src="@drawable/home" />

    <ImageButton
        android:id="@+id/news"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_toRightOf="@+id/home"
        android:background="#ffffff"
        android:onClick="news_Click"
        android:scaleType="fitXY"
        android:src="@drawable/database" />

    <ImageButton
        android:id="@+id/anons"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_toRightOf="@+id/news"
        android:background="#ffffff"
        android:onClick="annons_Click"
        android:scaleType="fitXY"
        android:src="@drawable/calendar" />

    <ImageButton
        android:id="@+id/faculty"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_toRightOf="@+id/anons"
        android:background="#ffffff"
        android:onClick="faculty_Click"
        android:scaleType="fitXY"
        android:src="@drawable/category" />

</RelativeLayout>



</RelativeLayout>
</android.support.v4.widget.DrawerLayout>

創建一個LinearLayout ,它是根布局的子項,並包裝所有其他布局,然后更改

<RelativeLayout
android:id="@+id/relativeLayout0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center" >

<RelativeLayout
android:id="@+id/relativeLayout0"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_vertical|center_horizontal|center" >

或者將android:layout_above="@+id/relativeLayout1"到LOGO布局中

這是我的代碼和我的布局。 我希望這就是你所需要的。 : -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@drawable/square_empty" >

    <RelativeLayout
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/square_empty" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/textView1"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="14dp"
            android:text="TextView" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="14dp"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="22dp"
            android:text="TextView" />
    </RelativeLayout>
</RelativeLayout>

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:src="@drawable/ic_launcher" />

<ImageButton
    android:id="@+id/imageButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageButton1"
    android:layout_toRightOf="@+id/imageButton1"
    android:src="@drawable/ic_launcher" />

<ImageButton
    android:id="@+id/imageButton3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageButton2"
    android:layout_toRightOf="@+id/imageButton2"
    android:src="@drawable/ic_launcher" />

<ImageButton
    android:id="@+id/imageButton4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageButton3"
    android:layout_toRightOf="@+id/imageButton3"
    android:src="@drawable/ic_launcher" />

這是快照: -

在此輸入圖像描述

嘗試將android:layout_above=@id/relativeLayout1到徽標布局中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM