2010-10-03 87 views
0

我是Android編程的新手,並且已經爲這個問題找到了很多答案,但我找不到答案。也許我使用了錯誤的搜索詞,因爲它看起來像是一個非常基本的請求。 我的設計(作爲示例),我會在我的相對佈局中定義兩個文本字段,然後是圖像,我希望圖像跨越屏幕的其餘部分。這是我到目前爲止:Android UI佈局問題

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
android:id="@+id/widget29" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<ImageView 
android:id="@+id/widget38" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_below="@+id/widget37" 
android:layout_alignParentLeft="true" 
> 
</ImageView> 
<TextView 
android:id="@+id/widget37" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="second view" 
android:layout_below="@+id/widget36" 
android:layout_alignParentLeft="true" 
> 
</TextView> 
<TextView 
android:id="@+id/widget36" 
android:layout_width="fill_parent" 
android:layout_height="50px" 
android:text="first view" 
android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true" 
> 
</TextView> 
</RelativeLayout> 

如何告訴我的ImageView跨越填充屏幕的其餘部分。如果我將高度和寬度定義爲「fill_parent」,則會填充兩個文本視圖。 在此先感謝您提供的任何幫助。

喬恩

回答

0

如果是RelativeLayout,那麼,你將不得不做這樣的事情在你的ImageView

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/id_of_your_second_textview" 
    android:layout_alignParentRight="true"/> 
2

看起來你只是堆放的觀點......在我看來,使用垂直LinearLayout而不是RelativeLayout可以更好地實現這種情況,因爲一個圖像視圖可以非常容易地跨越其餘空間而不會覆蓋文本視圖:

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

<TextView 
android:id="@+id/widget36" 
android:layout_width="fill_parent" 
android:layout_height="50px" 
android:text="first view" 
android:layout_weight="0" 
/> 

<TextView 
android:id="@+id/widget37" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="second view" 
android:layout_weight="0" 
/> 

<ImageView 
android:id="@+id/widget38" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_weight="1" 
/> 
</LinearLayout> 

在上例中,您使用佈局權重來強制屏幕空間的相對共享。將權重設置爲零將強制佈局管理器僅向兩個文本視圖提供請求的空間,並且由於圖像視圖設置爲填充父級(權重爲1),它將接收所有剩餘空間