【问题标题】:How to use complex layout in grid row如何在网格行中使用复杂布局
【发布时间】:2012-02-17 11:14:49
【问题描述】:

我在 resultlookup.xml 中有以下代码

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:id="@+id/layoutResultOuter"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:padding="5dp">
    <TextView
            android:id="@+id/txtResultLeadCode"
            style="@android:style/TextAppearance.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="ID" />
    <LinearLayout android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <TextView
                android:id="@+id/txtResultFirstName"
                style="@android:style/TextAppearance.Small"
                android:singleLine="true"  android:text="First Name" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        <TextView
                android:id="@+id/txtResultspace"
                style="@android:style/TextAppearance.Small"
                android:singleLine="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text=" " />
        <TextView
                android:id="@+id/txtResultLastName"
                style="@android:style/TextAppearance.Small"
                android:singleLine="true" android:text="Last Name" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </LinearLayout>
</LinearLayout>

现在,我希望在网格视图中使用此布局,作为它的第一行。网格是单列网格。

数据存储在 SQLite DB 中,我检索数据并必须以网格格式显示它。

阅读一些我可以使用“View Inflater”或“Layout Inflater”的地方。如果有任何示例代码,请告诉我。

我想要这样的东西:

【问题讨论】:

  • 问题已解决...在“适配器”类中使用了以下代码LinearLayout myLayout = (LinearLayout)findViewById(R.id.layoutResultOuter); LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); View hiddenInfo = inflater.inflate(R.layout.resultleadlookup, myLayout, false); addView(hiddenInfo);
  • 也在 XML 文件中使用了 。感谢@Ghost

标签: android layout layout-inflater


【解决方案1】:

我认为您可以简单地使用&lt;include&gt; 标签。 Here's 你是怎么做的。

【讨论】:

  • 我正在动态填充网格。这个在 XML 中是正确的
  • 是的。但是,您还没有提到动态填充视图。
  • LinearLayout myLayout = (LinearLayout)findViewById(R.id.layoutResultOuter); LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); View hiddenInfo = inflater.inflate(R.layout.resultleadlookup, myLayout, false); addView(hiddenInfo); 在网格适配器中
  • 链接现在已断开。这就是为什么您应该始终在答案中包含答案。外部链接应该是补充性的,答案应该能够独立存在。
【解决方案2】:

通过使用自定义适配器,您可以使用自己的布局来填充 GridView 中的项目。

使用上述布局作为项目并在 getView() 方法中对其进行充气,它将正常工作..

检查一次:custom adapter for grid view

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 2016-03-14
    相关资源
    最近更新 更多