簡體   English   中英

復雜的android布局(重疊,左/右對齊,居中對齊)

[英]Complex android layout (overlapping, left/right align, center align)

我必須在Android設備上創建以下布局:

布局

要求如下:第一個布局占據整個屏幕(fill_parent); 第二個(在屏幕底部)覆蓋第一個,並具有以下格式:

  • 3列;
  • 占據整個屏幕寬度;
  • 箭頭左右對齊,並根據屏幕寬度調整文本區域的大小;

我嘗試了很多事情,但是由於我是Android世界的新手,所以我還沒有成功。

這是我到目前為止的內容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="100"
    android:id="@+id/RootView">
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:id="@+id/mapImageView" />
    <LinearLayout
        android:id="@+id/bottomArea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">
        <LinearLayout
            android:id="@+id/adsArea"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true">
            <ImageButton
                android:src="@drawable/leftArrow"
                android:id="@+id/btnPrev"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="0dip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Title" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="This is some summary text" />
            </LinearLayout>
            <ImageButton
                android:src="@drawable/rightArrow"
                android:layout_alignParentRight="true"
                android:layout_marginRight="0dip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/btnNext" />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

但文字似乎沒有居中對齊,也沒有調整為屏幕寬度:

在此處輸入圖片說明

有人有線索嗎?

謝謝。

請在下面找到代碼。 另外,請勿將多個視圖組用於簡單的布局解決方案。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RootView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/mapImageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@android:drawable/ic_menu_gallery" />

    <RelativeLayout
        android:id="@+id/adsArea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <ImageButton
            android:id="@+id/btnPrev"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:src="@drawable/leftArrow" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Title" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="This is some summary text" />
        </LinearLayout>

        <ImageButton
            android:id="@+id/btnNext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@drawable/rightArrow" />
    </RelativeLayout>

</RelativeLayout>

使用此代碼作為所需的布局 ...

<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"
tools:context=".MainActivity" >

<LinearLayout
    android:id="@+id/linear1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linear2" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

<RelativeLayout
    android:id="@+id/linear2"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" >

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/rightButton1"
        android:layout_toRightOf="@+id/leftButton1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="This is some summary text" />

    </LinearLayout>

    <ImageButton
        android:id="@+id/rightButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>

暫無
暫無

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

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