【问题标题】:Set Buttons over ImageView - Android在 ImageView 上设置按钮 - Android
【发布时间】:2017-07-28 00:30:37
【问题描述】:

我有一个 FlowLayout,用户可以在其中添加品味,例如音乐、游戏、运动等。在用户告知他要添加的内容后,他单击一个按钮以将其显示在流布局中,因此,此过程必须以编程方式完成。创建图像,设置可绘制对象和大小。我做了一些。但现在我需要显示一个图像视图和一个按钮,以便用户可以删除添加的味道。我认为在 xml 中创建这个过程不会有帮助,因为用户可能不会添加任何口味。

我已经做了什么:

我必须做的:

我正在使用的方法:

ImageView iconLike = new ImageView(Register30.this);
                    iconLike.setImageResource(getIconLike(like));
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(getSizeIconLike());
                    lp.setMargins(5,5,5,5);
                    iconLike.setLayoutParams(lp);
                    Like newLike = new Like();
                    newLike.setIcon(iconLike);
                    newLike.setGenderFather(null);
                    newLike.setGenderChild(null);
                    newLike.setName(like);
                    likes.add(newLike);
                    likesContainer.addView(iconLike);

【问题讨论】:

  • 您应该在 XML 中创建它们并隐藏它们并以编程方式使它们不可点击。
  • 但是口味的数量是未知的。用户可以添加许多或不添加。当用户搜索它然后单击一个按钮添加它时,味道就会存在。
  • 使用 RecyclerView 创建任意数量的口味,或者没有。

标签: android button imageview drawable


【解决方案1】:

在 xml 2 文本视图中添加圆形背景

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">


     <ImageButton
        android:id="@+id/taste"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
      />

    <TextView
        android:id="@+id/remove"
        android:layout_width="width you want"
        android:layout_height="height you want"
        android:gravity="center"
        android:layout_gravity="end"
        android:background="@drawable/circle_background_with 
        _your_color"
        android:visibility="gone"/>

     <TextView
        android:id="@+id/add"
        android:layout_width="width you want"
        android:layout_height="height you want"
        android:gravity="center"
        android:layout_gravity="start"
        android:background="@drawable/circle_background_with 
        _your_color"
        android:visibility="gone"/>

</FrameLayout>

当用户长按口味时,只会改变文本视图的可见性。您需要在口味适配器中为每种口味设置长按功能。在此功能中,您可以在状态之间切换。

【讨论】:

  • 但是口味的数量是未知的。用户可以添加许多或不添加。当用户搜索它然后单击一个按钮添加它时,味道就会存在。
猜你喜欢
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-05
相关资源
最近更新 更多