我想在选项卡布局中放置按钮,并使用这些按钮在选项卡布局中调用不同的片段。此外,我想在每个按钮中放置一些图像。有人可以帮忙吗?
问问题
1681 次
1 回答
0
您可以在 xml 文件中使用 ImageButton 并将其与页面底部对齐,并从代码部分设置 ImageButton 的文本和背景图像。像这样的东西:
the_xml布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/theImageButton"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
在你的java代码中是这样的:
View v = (View) getActivity().getLayoutInflater().inflate(R.layout., null);
ImageButton ib = (ImageButton) v.findViewById(R.id.theImageButton);
ib.setBackgroundResource(R.drawable.X);
您可以使用 setBackgroundResource 方法定义一个随机更改背景的方法。
于 2014-08-02T13:44:18.993 回答