2013-01-17 76 views
1

![我輸入圖片描述] [1]我需要設置一個textview(及其背景),填充固定大小背景的設備的一半屏幕。我嘗試這個代碼,但我不能。目標是:半屏幕,向上顯示圖像,沿着textview。背景textview半屏

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

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/luna" 
     android:textSize="15pt" /> 

    <ScrollView 
     android:id="@+id/scrollView10" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="#000000" > 

     <TextView 
      android:id="@+id/textView10" 
      android:layout_width="match_parent" 
      android:layout_height="320dp" 
      android:background="#000000" 
      android:gravity="center" 
      android:textColor="#ffffff" 
      android:textSize="14sp" 
      android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl" 
      android:autoLink="web|email" 
      android:textStyle="italic" /> 
    </ScrollView> 
</LinearLayout> 

<Button 
    android:id="@+id/button10" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Chiudi" /> 

    </LinearLayout> 

回答

2

您可以通過添加權重來實現此目的。

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

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/luna" 
    android:textSize="15pt" 
    android:layout_weight="1"/> 

<ScrollView 
    android:id="@+id/scrollView10" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:background="#000000" 
    android:layout_weight="1" > 

    <TextView 
     android:id="@+id/textView10" 
     android:layout_width="match_parent" 
     android:layout_height="320dp" 
     android:background="#000000" 
     android:gravity="center" 
     android:textColor="#ffffff" 
     android:textSize="14sp" 
       android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl" 
     android:autoLink="web|email" 
     android:textStyle="italic" /> 
</ScrollView> 
</LinearLayout> 

<Button 
android:id="@+id/button10" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:text="Chiudi" /> 

</LinearLayout> 
+0

感謝您的回覆。似乎沒關係,但圖像丟失比例 –

+0

我認爲你不需要在這裏的ScrollView。因爲如果TextView中的文本超過了它的高度,可以在textView –

+0

中啓用滾動,謝謝!圖像不保持比例。我修好了嗎? –

0
檢查

此:

我已經改變了內線性佈局相對佈局。我認爲它會給你想要的結果:

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

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <ScrollView 
      android:id="@+id/scrollView10" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_gravity="center" 
      android:background="#000000" > 

      <TextView 
       android:id="@+id/textView10" 
       android:layout_width="match_parent" 
       android:layout_height="320dp" 
       android:autoLink="web|email" 
       android:background="#000000" 
       android:gravity="center" 
       android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl" 
       android:textColor="#ffffff" 
       android:textSize="14sp" 
       android:textStyle="italic" /> 
     </ScrollView> 

     <ImageView 
      android:id="@+id/img" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_above="@id/scrollView10" 
      android:background="@drawable/luna" 
      android:textSize="15pt" /> 
    </RelativeLayout> 

    <Button 
     android:id="@+id/button10" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Chiudi" /> 

</LinearLayout> 

我先定義了scrollview。然後我用match_parent大小定義ImageView。所以它佔用了屏幕的所有剩餘空間。這樣,圖像比例也是適當的。希望能幫助到你。

+0

謝謝你的答案。圖像再次沒有保持其比例。 –

+0

@PolHallen,你可以發佈快照嗎?因爲它在我的工作正常。 –

+0

我加了截圖,就像你看到的,月亮不像應該是圓的。謝謝 –