2014-02-17 64 views
-1

我要像下面的圖片enter image description hereAndroid的佈局修復

,但現在我越來越喜歡這個

enter image description here

此佈局在主XML文件中使用我的代碼的機器人頂部的菜單部分。

<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:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/back_gradient" 
     android:orientation="horizontal" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu" 
      android:background="@drawable/back_gradient" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="fill_vertical" 
      android:background="@drawable/back_gradient" 
      android:text="Welcome" 
      android:textAlignment="center" 
      android:textColor="#ffffff" 
      android:textSize="19sp" 
      android:gravity="center_vertical" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="20dp" 
      android:src="@drawable/search" /> 

    </LinearLayout> 

</RelativeLayout> 

有誰能告訴我我該如何實現它?

在此先感謝

回答

1

TextView

<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:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/back_gradient" 
     android:orientation="horizontal" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu" 
      android:background="@drawable/back_gradient" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp"   //here 
      android:layout_weight="1"   //here 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:background="@drawable/back_gradient" 
      android:text="Welcome" 
      android:textAlignment="center" 
      android:textColor="#ffffff" 
      android:textSize="19sp" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="20dp" 
      android:src="@drawable/search" /> 

    </LinearLayout> 

</RelativeLayout> 
0

使用android:gravity="center_horizontal"android:layout_weight="1"試試這個..

修正爲您TextView。 嘗試以下數據

<TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="fill_vertical" 
      android:background="#123456" 
      android:text="Welcome" 
      android:layout_weight="1" 
      android:textAlignment="center" 
      android:textColor="#ffffff" 
      android:textSize="19sp" 
      android:gravity="center_horizontal" /> 
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" 
android:background="@drawable/back_gradient" 
tools:context=".MainActivity" > 

<ImageButton 
    android:id="@+id/imageButton1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:background="@drawable/back_gradient" 
    android:src="@drawable/menu" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_toLeftOf="@+id/imageView1" 
    android:layout_toRightOf="@+id/imageButton1" 
    android:background="@drawable/back_gradient" 
    android:gravity="center_vertical" 
    android:text="Welcome" 
    android:textAlignment="center" 
    android:textColor="#ffffff" 
    android:textSize="19sp" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_marginEnd="20dp" 
    android:src="@drawable/search" /> 

</RelativeLayout> 
0

使用此佈局

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/back_gradient" 
     android:orientation="horizontal" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu" 
      android:background="@drawable/back_gradient" /> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:background="@drawable/back_gradient" 
      android:text="Welcome" 
      android:textAlignment="center" 
      android:textColor="#ffffff" 
      android:layout_weight="1" 
      android:textSize="19sp" 
      android:gravity="center" /> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="20dp" 
      android:src="@drawable/search" /> 

    </LinearLayout> 

注:不包括在此xml相對佈局。

0

通過將0dip設置爲android:layout_width並設置android:layout_weight="1"來修改您的TextView。所以,更新後的TextView XML如下...

<TextView 
     android:id="@+id/textView1" 
     android:layout_width="0dip" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_gravity="fill_vertical" 
     android:background="@drawable/back_gradient" 
     android:text="Welcome" 
     android:textAlignment="center" 
     android:textColor="#ffffff" 
     android:textSize="19sp" 
     android:gravity="center_vertical" /> 
1

試試這個佈局。

<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:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/back_gradient" 
    android:orientation="horizontal" > 

    <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/menu" 
     android:layout_weight="1" 
     android:background="@drawable/back_gradient" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="fill_vertical" 
     android:background="@drawable/back_gradient" 
     android:text="Welcome" 
     android:textAlignment="center" 
     android:textColor="#ffffff" 
     android:textSize="19sp" 
     android:layout_weight="1" 
     android:gravity="center_vertical" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="20dp" 
     android:layout_weight="1" 
     android:src="@drawable/search" /> 

</LinearLayout>