2013-04-23 72 views
0

我必須創建一個Android設備上如下的佈局:複雜機器人佈局(重疊,左/右對齊,中心對齊)

Layout

的要求如下: 第一佈局佔據該整個屏幕(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> 

但文字似乎並沒有被中心對齊,也沒有調整到屏幕寬度:

enter image description here

是否有人有線索?

謝謝。

+3

後不管你已經試過,準確地似乎沒有什麼在合作。雖然我必須承認,我喜歡你發佈的圖形! – SudoRahul 2013-04-23 06:03:21

+1

你有什麼嘗試?如果您遇到任何問題,請向我們展示問題快照/代碼。 – 2013-04-23 06:07:06

回答

0

請找到下面的代碼。希望能幫助到你。此外,請勿將多個視圖組用於簡單佈局解決方案。

<?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> 

希望它有幫助。

0

使用此代碼,您需要的佈局 ...

<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>