【问题标题】:Android XML tableLayout and Gallery problemAndroid XML tableLayout 和 Gallery 问题
【发布时间】:2011-06-27 03:06:23
【问题描述】:

我写了这段 XML 代码;

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:layout_weight="20" 
>
<TableRow 
    android:layout_height="fill_parent"
    android:layout_weight="10" 
    android:layout_width="fill_parent">`enter code here`</TableRow>
<TableRow 
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" 
    android:layout_weight="9">
    <Gallery 
    android:layout_height="fill_parent" 
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_weight="1">
    </Gallery>
</TableRow>
<TableRow 
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    > 
    <Button 
        android:id="@+id/Button1" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:gravity="center"
        android:layout_weight="1"
        >
    </Button>
    <Button 
        android:id="@+id/Button2" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:gravity="center"
        android:layout_weight="1">
    </Button>
    <Button 
        android:id="@+id/Button3" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:gravity="center"
        android:layout_weight="1">
    </Button>
    <Button 
        android:id="@+id/Button4" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:gravity="center"
        android:layout_weight="1">
    </Button>
</TableRow>

此代码按我想要的方式显示,但是当我运行代码时,按钮的大小会随着画廊中的图像大小而变化。如何编写彼此独立的 XML 代码(画廊和按钮)。 感谢帮助

【问题讨论】:

    标签: android xml android-layout gallery tablelayout


    【解决方案1】:

    我建议您使用 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:orientation="vertical">
        <Gallery 
            android:layout_height="fill_parent" 
            android:id="@+id/gallery"
            android:layout_width="fill_parent"
            android:layout_weight="1">
        </Gallery>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
            <Button 
                android:id="@+id/Button1" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:gravity="center"
                android:layout_weight="1">
            </Button>
            <Button 
                android:id="@+id/Button2" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:gravity="center"
                android:layout_weight="1">
            </Button>
            <Button 
                android:id="@+id/Button3" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:gravity="center"
                android:layout_weight="1">
            </Button>
            <Button 
                android:id="@+id/Button4" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:gravity="center"
                android:layout_weight="1">
            </Button>
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 我试过你的推荐,但看起来一样。你能把代码发给你吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多