[英]How add multiple TextView inside an ImageButton?
是否可以在一个带有颜色背景的 ImageButton 中添加多个 TextView ?
核心需要是有一个带有动作文本的按钮,以及一个解释动作或提供与动作相关的其他信息的潜台词。 这个潜台词可能会不时变化。
考虑到这一要求,一种解决方案是在下方设置一个普通按钮和一个潜台词,不可点击。 但是我觉得很乱。 我喜欢的一个更好的方法是,例如在 iOS 上,有一个可点击的 UIView,其中包含粗体文本的操作和浅文本的解释。 请参阅下面包含 4 个按钮的图像:
如何使用 Java 在 Android 上实现相同的目标? 我能拥有的最接近的是在 TextView 下方放置一个 ImageButton,这听起来不太对。
可以在 ImageButton 内嵌套 TextViews 吗? 如果没有,最好的选择是什么?
我希望这可能是有用的,它解释了如何在 XML 中的 imageView 内部和前面放置 textView。
ImageButton/ImageView XML 中的 TextView - Android Dev
显然,请确保每个视图都有一个唯一的 ID/名称,您可以按照此链接的此处所示进行分配
抱歉,我自己无法具体解释,但自从用 Java 为 Android 开发以来已经有一段时间了。
我不知道你为什么想要这种行为,但你可以为你的视图创建一个容器并向整个视图添加一个点击监听器。 你也可以在任何地方使用它。
这方面的一个例子是。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:background="@drawable/container_background"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="0.33"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="0.33"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="0.33"
/>
添加选择器背景
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/text_pressed" />
<item android:color="@color/normal" />
</selector>
和听者
findViewById(R.id.container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.