这个xaml网格在Android上相当于什么? [英] What is the Android equivalent of this xaml grid?

查看:87
本文介绍了这个xaml网格在Android上相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android中进行以下布局(只是开始).

I would like to make the following layout in Android (just starting).

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />            
    </Grid.RowDefinitions>

    <TextBlock Text="Text1" Grid.Row="0" />

    <ListBox Grid.Row="1" />

    <StackPanel Orientation="Horizontal" Grid.Row="2">
        <Button Content="Button 1" />
        <Button Content="Button 2" />
    </StackPanel>

</Grid>

我到此为止,但是按钮没有显示在屏幕上.看来我的方法无法提供相当于星形行的内容.

I got this far, but the buttons don't show up on screen. It seems that I can't have something equivalent to a star-sized row with my approach.

<?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="wrap_content">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:text="@string/AppName"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView1"
            android:gravity="center_horizontal" />
        <ListView
            android:minHeight="25px"
            android:layout_width="fill_parent"
            android:id="@+id/listView1"
            android:choiceMode="multipleChoice"
            android:drawSelectorOnTop="true"
            android:layout_height="fill_parent"
            android:layout_below="@id/textView1" />

        <LinearLayout
            android:layout_below="@id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:text="Button"
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent" />
            <Button
                android:text="Button"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:id="@+id/button2"
                android:gravity="center_vertical"
                android:layout_gravity="right" />
        </LinearLayout>

    </RelativeLayout>
</LinearLayout>

有人可以向我解释吗?

谢谢!

推荐答案

尝试一下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:text="AppName"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"
        android:gravity="center_horizontal" />
    <LinearLayout
        android:id="@+id/bottomLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
        <Button
            android:text="Button"
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_weight="50"
            android:layout_height="match_parent" />
        <Button
            android:text="Button"
            android:layout_width="0dp"
            android:layout_weight="50"
            android:layout_height="match_parent"
            android:id="@+id/button2" />
    </LinearLayout>
    <ListView
        android:minHeight="25px"
        android:layout_width="fill_parent"
        android:id="@+id/listView1"
        android:choiceMode="multipleChoice"
        android:drawSelectorOnTop="true"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="false"
        android:layout_above="@id/bottomLayout"
        android:layout_below="@id/textView1" />
</RelativeLayout>

listView1上的"fill_parent"将带有按钮的布局推到屏幕外部.我将布局移到了ListView的顶部,并使其与父级的底部对齐(否则它们将显示在顶部).

The "fill_parent" on listView1 was pushing the layout w/ buttons outside the screen. I moved the layout on top of the ListView and made it to align with the bottom of the parent (otherwise they would show up at top).

android:layout_alignParentBottom="true"

然后使ListView除了在textView1的底部之外,还可以在bottomLayout的顶部对齐.

Then made the ListView align on top of the bottomLayout in addition to being at bottom of textView1.

android:layout_above="@id/bottomLayout"
android:layout_below="@id/textView1"

这篇关于这个xaml网格在Android上相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆