【问题标题】:How to map two layout in android如何在android中映射两个布局
【发布时间】:2016-04-10 03:58:10
【问题描述】:

我在 xml 中有 2 个布局。

XML:

<TableLayout
        android:id="@+id/table"
        android:layout_width="fill_parent"
        android:layout_height="470dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="35dp"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp">
</TableLayout>
<FrameLayout
         android:id="@+id/imageLayout"
         android:layout_width="fill_parent"
         android:layout_height="470dp"
         android:layout_alignParentBottom="true"
         android:layout_marginBottom="35dp"
         android:layout_marginLeft="35dp"
         android:layout_marginRight="45dp"
         android:layout_marginTop="45dp">
</FrameLayout>

表格布局用于创建 10X4 单元格--http://i.stack.imgur.com/hYPLT.png FrameLayout 用于在 10X4 单元格上显示图像。现在正在做拖放图像,如何在 TableLaout 的哪个单元格中找到图像?

【问题讨论】:

    标签: android android-layout android-xml android-design-library


    【解决方案1】:

    如果您只需要显示提供的链接中的图像的 4 部分,那么您可以使用这样的表格布局:-

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

    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">
    
        <ImageView
            android:id="@+id/imv1"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:src="@drawable/ic_manual_icon"
            />
    
        <ImageView
            android:id="@+id/imv2"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:src="@drawable/ic_manual_icon"
            />
    
    </TableRow>
    
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">
    
        <ImageView
            android:id="@+id/imv3"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:src="@drawable/ic_manual_icon"
            />
    
        <ImageView
            android:id="@+id/imv4"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:src="@drawable/ic_manual_icon"
            />
    
    </TableRow>
    

    像上面一样,您可以在您的活动或片段中找到图像视图参考,您可以在它们上为其设置图像资源。

    如果您有更多行数的表格,那么使用 GridView 应该会更好。 有关 GridView 的更多信息,请参阅here

    【讨论】:

    • 我需要 10X4 网格并在该网格上拖放,如果更改意味着需要在两个或多个单元格中显示,图像大小可以更改
    【解决方案2】:

    如果你可以使用 GridView 而不是 TableLayout 检查这个https://blahti.wordpress.com/2011/10/03/drag-drop-for-android-gridview/答案

    【讨论】:

    • 我需要 10X4 网格并在该网格上拖放,如果更改意味着需要在两个或多个单元格中显示,图像大小可以更改
    • 你检查给定的链接了吗
    • 使用给定的链接作为参考不完全作为答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    相关资源
    最近更新 更多