Как сделать так, чтобы изображение отображалось до половины экрана каждого устройства? - PullRequest
1 голос
/ 14 ноября 2011

В моем файле .xml у меня есть этот формат:

<LinearLayout android:layout_orientation="vertical"...>

<ImageView>...
</ImageView>

<ScrollView ...>

    <TableLayout..>
    </TableLayout>

</ScrollView>


</LinearLayout>

для imageView, я хотел бы иметь высоту до половины экрана (при любом размере экрана), а затем запустить мой tableLayoutв другой половине экрана! Это возможно? спасибо

Ответы [ 3 ]

2 голосов
/ 14 ноября 2011

Использовать Layout_weight.

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

    <ImageView android:layout_height="wrap_content" android:src="@drawable/icon"
        android:layout_width="fill_parent" android:layout_weight="1"
        android:background="#ffffff">
    </ImageView>

    <ScrollView android:layout_height="wrap_content"
        android:layout_width="fill_parent" android:layout_weight="1"
        android:background="#ff0000">

    </ScrollView>

</LinearLayout>][1]

Это дает вид, который вы ищете.

0 голосов
/ 22 ноября 2011

Попробуйте:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imageView1" android:src="@drawable/icon"
    android:layout_height="0dp" android:layout_width="fill_parent"
    android:layout_weight="1"></ImageView>
<ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView1"
    android:layout_weight="1" android:layout_height="0dp">
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
    <TextView
        android:text="Open"
        android:padding="3dip" />
    <TextView
        android:text="New"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>

<TableRow>
    <TextView
        android:text="Save"
        android:padding="3dip" />
    <TextView
        android:text="Exit"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
0 голосов
/ 14 ноября 2011

Вы можете использовать свойство android: layout_weight, чтобы указать, сколько места должно занимать каждое дочернее представление.Посмотрите @ http://developer.android.com/guide/topics/ui/layout-objects.html, специально для линейной части для деталей.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...