问:请帮助设计带有附加图像的布局。请找到所附的屏幕截图以供参考
建议我们选择网格布局还是相对布局。请提供相应的xml布局。
如果您建议使用网格布局,请提供用户界面并帮助执行onclick侦听器,以从该网格布局导航相应的活动。
答:在可绘制文件夹中创建形状,例如
<shape xmlns:android =“ http://schemas.android.com/apk/res/android”
android:shape =“ rectangle”>
<角
android:radius =“ 10dip” />
<固体
android:color =“#F00” />
<行程
android:width =“ 2dip”
android:color =“#FFF” />
<填充
android:left =“ 5dip”
android:right =“ 5dip”
android:top =“ 5dip”
android:bottom =“ 5dip” />
</ shape>
现在,在您的xml文件中创建一个Text视图,并将其背景设置为上面创建的形状。
<TextView
android:layout&#95; width =“ wrap&#95; content”
android:layout&#95; height =“ wrap&#95; content”
android:text =“ 10”
android:textColor =“#FFF”
android:textSize =“ 16sp”
android:textStyle =“ bold”
android:background =“ @ drawable / badge&#95; circle” />
这将产生带有红色背景的文本视图效果,现在将其设置为任何视图(如按钮或文本等)的角。
例如
<RelativeLayout xmlns:android =“ http://schemas.android.com/apk/res/android”
android:layout&#95; width =“ wrap&#95; content”
android:layout&#95; height =“ wrap&#95; content”>
<按钮
android:id =“ @ + id / myButton”
android:layout&#95; width =“ 65dip”
android:layout&#95; height =“ 65dip” />
<TextView
android:id =“ @ + id / textOne”
android:layout&#95; width =“ wrap&#95; content”
android:layout&#95; height =“ wrap&#95; content”
android:layout&#95; alignTop =“ @ id / myButton”
android:layout&#95; alignRight =“ @ id / myButton”
android:text =“ 10”
android:textColor =“#FFF”
android:textSize =“ 16sp”
android:textStyle =“ bold”
android:background =“ @ drawable / badge&#95; circle” />
</ RelativeLayout>
请替换&#95;