2013-04-23 74 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>