【发布时间】:2015-03-09 06:38:28
【问题描述】:
我需要在我的 FragmentTabHost 背景图像中设置非矩形或方形图像,如下所示:http://i.imgur.com/yWbDi0a.jpg?1。
但我得到了这个:http://i.imgur.com/g1jvmsb.png?1(选项卡之间的默认分隔符正在剪切我的图像):(请帮助
我有这些对角线形状的图像,我想在我的各个选项卡中将它们设置为背景图像。这是我迄今为止所做的。
tab_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
</LinearLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost) findViewById(R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabFrameLayout);
mTabHost.addTab(
mTabHost.newTabSpec("tab1").setIndicator(getTabIndicator(mTabHost.getContext(), R.drawable.tab1)),
FragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("tab2").setIndicator(getTabIndicator(mTabHost.getContext(), R.drawable.tab2)),
FragmentTab.class, null);
}
private View getTabIndicator(Context context, int icon) {
View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
ImageView iv = (ImageView) view.findViewById(R.id.imageView);
iv.setImageResource(icon);
return view;
}
}
【问题讨论】:
-
你和this一样吗?
-
是的,但我的图像不是完美的矩形,它们有点对角线。请看图片链接。谢谢。
-
是的,我见过他们。您必须为它们制作自定义标签。
-
您可以使用 TabWidget 并通过设置分隔线颜色使分隔线透明
-
@user2787602 你解决了吗?