Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在android中制作椭圆形tabhost大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试着按照预期的形状制作椭圆形tabhost.

我尝试了以下代码.

public class AndroidTabLayoutActivity extends tabactivity {
    TabHost tabHost;

    @Override
    public void onCreate(Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);
        setContentView(R.layout.main);

        tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;
        intent = new Intent().setClass(this,PhotosActivity.class);
        View tabView = createTabView(this,"updates");
        spec = tabHost.newTabSpec("tab1").seTinDicator(tabView).setContent(intent);
        tabHost.addTab(spec);

        tabView = createTabView(this,"Events");
        intent = new Intent().setClass(this,SongsActivity.class);
        spec = tabHost.newTabSpec("tab2").seTinDicator(tabView)
                .setContent(intent);
        tabHost.addTab(spec);

        TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
        final int tabChildrenCount = tabWidget.getChildCount();
        View currentView;
        for (int i = 0; i < tabChildrenCount; i++) {
            currentView = tabWidget.getChildAt(0);
            LinearLayout.LayoutParams currentLayout =
                    (LinearLayout.LayoutParams) currentView.getLayoutParams();
            currentLayout.setMargins(0,16,0);
        }
        tabWidget.requestLayout();
        tabHost.getTabWidget().setDividerDrawable(null);
    }

    private static View createTabView(Context context,String tabText) {
        View view = LayoutInflater.from(context).inflate(R.layout.custom_tab,null,falsE);
        TextView tv = (TextView) view.findViewById(R.id.tabtitleText);
        tv.setText(tabText);
        return view;
    }
}
@H_39_2@main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://scheR_225_11845@as.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:BACkground="#2CA0E6">

<LinearLayout xmlns:android="http://scheR_225_11845@as.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="30dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp">

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="2dp">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:paddingTop="5dp">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="70dp" />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </LinearLayout>
    </TabHost>
</LinearLayout>

custom_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://scheR_225_11845@as.android.com/apk/res/android"
android:id="@+id/tabtitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:clickable="true"
android:padding="5dp"
android:textSize="15sp"
android:textStyle="bold"
android:layout_gravity="center"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="@color/tab_textcolor"
android:BACkground="@drawable/tab_SELEctor"/>

我得到的输出如下image70001

任何人都可以帮助,如何做到这一点.谢谢

解决方法

那是一个图像.你需要做的就是准备好图像并将它们设置到选定的标签.就是这样!

好吧,我没有那个图像,所以我使用下面的图像(SELEcted.png,not_SELEcted.png)只是为了说明它是如何工作的,但它们设计得不好;)

P.surrentLayout.setMargins(0,this_should_be_zero,0);并且您的图像应该具有该边距(无论预期的间隙),否则两个图像之间将存在间隙.
此外,您可以使用选择器(与另一种颜色相同的png)来显示所选的一个.

似乎你试图找出一种编程方式,如果你有额外的时间和时间,可以尝试使用Paint类进行解决方法.努力,如果你使用形状将很难弄清楚确切的视图,因为它很复杂,你可以看到标签A视图和B不相同,使用图像将是最简单的

并在您的custom_tab.xml集中

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://scheR_225_11845@as.android.com/apk/res/android"
    android:id="@+id/tabtitleText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:clickable="true"
    android:padding="5dp"
    android:textSize="15sp"
    android:textStyle="bold"
    android:layout_gravity="center"
    android:ellipsize="marquee"
    android:MaxLines="1"   //  you can use this instead  of  android:singleLine="true" 
    android:textColor="@color/black"
    android:BACkground="@drawable/tab_button_effect"/> // here set SELEctor

tab_button_effect.xml

<?xml version="1.0" encoding="utf-8"?>
<SELEctor xmlns:android="http://scheR_225_11845@as.android.com/apk/res/android">

    <item android:drawable="@drawable/not_SELEcted" android:state_SELEcted="true"></item>
    <item android:drawable="@drawable/SELEcted"></item>

</SELEctor>

大佬总结

以上是大佬教程为你收集整理的如何在android中制作椭圆形tabhost全部内容,希望文章能够帮你解决如何在android中制作椭圆形tabhost所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。