2013-10-30 90 views
0

我在我的活動中使用了LinearLayout,因爲我需要顯示另一個包含要顯示在底部的圖像的LinearLayout。Android:如何在佈局的底部放置一個顯示圖像的線性佈局?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:background="@drawable/gamelevelscreen" 
android:orientation="vertical" > 
....... 
      <LinearLayout 
      android:id="@+id/linearLayout_AdMob" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"   
      android:orientation="horizontal" 
      android:layout_gravity="bottom" 
      android:layout_alignParentBottom="true" 
      android:gravity="center"> 
      </LinearLayout> 
</LinearLayout> 

但是圖像並沒有完全對齊在底部。它略高於底部。 我已經完成了佈局設計,現在將進行大量的返工。請給出解決方案,使其僅在LinearLayout中發生。

+1

'機器人:layout_alignParentBottom = 「真」'在'LinearLayout'沒有影響。考慮使用'RelativeLayout'來代替。 –

+0

@antimo在LinearLayout中不可能這樣做嗎?我已經完成了佈局設計,並且現在要進行大量的返工工作。 – user2674084

+0

您可以在'LinearLayout'中使用'android:layout_weight'來填充剩餘的空間,然後用'android:gravity =「bottom」' –

回答

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/linearLayout_AdMob" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:gravity="center" 
    android:orientation="horizontal" > 

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


</RelativeLayout> 
0

試試這個..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/gamelevelscreen" 
android:orientation="vertical" > 
      <LinearLayout 
      android:id="@+id/linearLayout_AdMob" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"   
      android:orientation="horizontal" 
      android:gravity="center" 
      android:layout_alignParentBottom="true"> 
      </LinearLayout> 
</RelativeLayout> 
1

使用相對佈局而不是線性佈局或使用權的線性佈局做這個。 試試吧,它一定會幫助你。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relativeLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

> 

<LinearLayout 
    android:id="@+id/linearLayout_AdMob" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:gravity="center" 
    android:orientation="horizontal" > 

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


</RelativeLayout> 
0
// try this 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="5dp" 
    android:orientation="vertical" > 
    <LinearLayout 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="1"> 

     </LinearLayout> 
    <LinearLayout 
     android:id="@+id/linearLayout_AdMob" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 
     <ImageView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:adjustViewBounds="true" 
      android:src="@drawable/ic_launcher"/> 
    </LinearLayout> 
</LinearLayout> 
相關問題