【问题标题】:Equivalent control in Android to WPF GridAndroid 中与 WPF Grid 的等效控件
【发布时间】:2014-05-25 21:38:18
【问题描述】:

我觉得问这个很愚蠢,但我无处可寻。我习惯了 C# 和 XAML,但我开始使用 Android 开发,所以我是 Java 和 XML 的新手,我感到很迷茫。 最接近 WPF 网格的控件是什么? 如何通过代码和 XML 定义?

【问题讨论】:

    标签: android xml wpf grid equivalent


    【解决方案1】:

    好吧,另一个可能的解决方案是使用LinearLayout,然后根据需要设置子元素的layout_weight,但请确保将子元素的layout_height设置为0dp

    例如:

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".5" />
    
        <TextView 
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:text="SomeText"
                android:layout_weight=".5"/>
    
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      您可能正在寻找GridLayout,这在this blog post 中有完整的实现示例。

      请注意,GridLayout 最初是在 API 14,冰淇淋三明治中引入的。如果您需要支持旧设备,您可以使用 Support Library 等效项 android.support.v7.widget.GridLayout,正如其包名称所暗示的那样,它支持回 API 7。您需要按照 these instructions 将支持 GridLayout 添加到您的项目中.

      【讨论】:

        猜你喜欢
        • 2023-03-21
        • 2019-04-16
        • 2013-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多