小编f.t*_*ski的帖子

在水平线性布局中添加新行

我正在以水平方向的线性布局创建动态图像。我在用:

ImageView imageView = new ImageView(getContext());
            imageView.setLayoutParams(new 
android.view.ViewGroup.LayoutParams(200,200));
            imageView.setOnTouchListener(new MyTouchListener());
            imageView.setOnDragListener(new MyDragListener());
            setImageIcon(imageView, ap.getPackageName());
            topLayout.addView(imageView);
Run Code Online (Sandbox Code Playgroud)

但在屏幕的末尾,它继续在右侧无限添加图标。我想添加边框并从新行开始。有什么选项可以做到这一点吗?这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/master_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="4"
        android:columnWidth="320dp"
        android:orientation="vertical"
        android:rowCount="8"
        android:stretchMode="columnWidth">

<LinearLayout
    android:id="@+id/top_layout"
    android:layout_width="match_parent"
    android:layout_height="280dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/shape_droptarget_grey"
    android:gravity="left"
    android:orientation="horizontal">
    <TextView android:id="@+id/text_top"
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:clickable="false"
              android:text="Security upgrade avaliable"
              android:textAlignment="center"
              android:textSize="28dp"/>

</LinearLayout>


<LinearLayout
    android:id="@+id/bottom_layout"
    android:layout_width="match_parent"
    android:layout_height="280dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/shape_droptarget_green"
    android:gravity="left"
    android:orientation="horizontal">
    <TextView android:id="@+id/text_bottom"
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:clickable="false"
              android:gravity="center"
              android:text="Secured Apps"
              android:textAlignment="center"
              android:textSize="28dp"/>

</LinearLayout>


</GridLayout>
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout

0
推荐指数
1
解决办法
3366
查看次数

标签 统计

android ×1

android-linearlayout ×1