![在此处输入图像说明] [1]我需要设置一个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>
答案 0 :(得分: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>
答案 1 :(得分: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。因此它占用了屏幕的所有剩余空间。这样,图像比例也会合适。希望它有所帮助。