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" >

<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>
4

2 回答 2

1

您可以通过添加权重来实现这一点。

 <?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>
于 2013-01-17T08:18:38.177 回答
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>

我首先定义了滚动视图。然后我用 match_parent 大小定义了 ImageView。所以它占用了屏幕的所有剩余空间。这样,图像比例也将是适当的。希望能帮助到你。

于 2013-01-17T09:28:48.783 回答