Android 标签小部件

发布于 2024-11-14 12:48:28 字数 1359 浏览 3 评论 0原文

我需要在我的应用程序中创建选项卡,我使用了以下工作良好...但我需要它显示为选项卡查看iPhone如何使用android 1.6?提前致谢..

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
    android:id="@+id/tab"    android:orientation="vertical"        android:layout_width="fill_parent"   android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"    android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"            android:layout_width="fill_parent"     android:layout_height="fill_parent">

        <LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:orientation="vertical"/>

        <LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:orientation="vertical"/>

这是我的选项卡看起来像..
但是,我需要删除它们之间的空格,我希望它看起来像

查询 2 如果我使用意图在两个活动之间切换..第二个活动需要 oncreate 方法,它是强制性的吗?

i need to create tab in my application i've used the following working good... but i need it to display as tabs look into the iphone how it can possible it using android 1.6? thanks in advance..

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
    android:id="@+id/tab"    android:orientation="vertical"        android:layout_width="fill_parent"   android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"    android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"            android:layout_width="fill_parent"     android:layout_height="fill_parent">

        <LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:orientation="vertical"/>

        <LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:orientation="vertical"/>

here is my tab looks like..
but,i need to remove the space between them i want it look like this

Query 2
if i am using intent to switch between 2 activities.. the 2nd activity need oncreate method is it it compulsory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来是傀儡 2024-11-21 12:48:28

tab.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/tab_background_selector" android:gravity="center"
android:orientation="vertical" android:padding="5dp">
<ImageView android:id="@+id/tab_icon" android:layout_width="30dp"
    android:layout_height="30dp" android:scaleType="fitCenter" />
<TextView android:id="@+id/tab_text" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:singleLine="true"
    android:textStyle="bold" android:gravity="center_horizontal"
    android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee"
    android:textColor="@drawable/tab_text_selector" />

ma​​in.xml

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_alignParentBottom="true">
    <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <HorizontalScrollView android:scrollbars="none"
                android:layout_width="fill_parent" android:layout_height="wrap_content">
                <TabWidget android:id="@android:id/tabs" 
                android:layout_alignParentBottom="true"
                    android:layout_width="fill_parent" android:layout_height="wrap_content" />
            </HorizontalScrollView>
            <FrameLayout android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
</LinearLayout> 

TestActivity.java

setContentView(R.layout.maiin);  
         final TabHost tabHost = (TabHost) getTabHost();
            tabHost.addTab(createTab(MobiintheMorningActivity.class, 
                    "Welcome", "Welcome", R.drawable.icon));
            tabHost.addTab(createTab(SongList.class, 
                    ".Mp3List", ".Mp3List", R.drawable.icon));
            tabHost.addTab(createTab(AboutUs.class, 
                    "AboutUs", "AboutUs", R.drawable.icon));
            tabHost.addTab(createTab(ExtraInfromation.class, 
                    "Extra", "Extra", R.drawable.icon));


            tabHost.setCurrentTab(0);
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
            tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
            tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
            tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;        
        }
        private TabSpec createTab(final Class<?> intentClass, final String tag, 
                final String title, final int drawable)
        {
            final Intent intent = new Intent().setClass(this, intentClass);

            final View tab = LayoutInflater.from(getTabHost().getContext()).
                inflate(R.layout.tab, null);
            ((TextView)tab.findViewById(R.id.tab_text)).setText(title);
            ((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);

            return getTabHost().newTabSpec(tag).setIndicator(tab).setContent(intent);
        }
    }

这是完整的工作代码:Pragna

tab.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/tab_background_selector" android:gravity="center"
android:orientation="vertical" android:padding="5dp">
<ImageView android:id="@+id/tab_icon" android:layout_width="30dp"
    android:layout_height="30dp" android:scaleType="fitCenter" />
<TextView android:id="@+id/tab_text" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:singleLine="true"
    android:textStyle="bold" android:gravity="center_horizontal"
    android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee"
    android:textColor="@drawable/tab_text_selector" />

main.xml

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_alignParentBottom="true">
    <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <HorizontalScrollView android:scrollbars="none"
                android:layout_width="fill_parent" android:layout_height="wrap_content">
                <TabWidget android:id="@android:id/tabs" 
                android:layout_alignParentBottom="true"
                    android:layout_width="fill_parent" android:layout_height="wrap_content" />
            </HorizontalScrollView>
            <FrameLayout android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
</LinearLayout> 

TestActivity.java

setContentView(R.layout.maiin);  
         final TabHost tabHost = (TabHost) getTabHost();
            tabHost.addTab(createTab(MobiintheMorningActivity.class, 
                    "Welcome", "Welcome", R.drawable.icon));
            tabHost.addTab(createTab(SongList.class, 
                    ".Mp3List", ".Mp3List", R.drawable.icon));
            tabHost.addTab(createTab(AboutUs.class, 
                    "AboutUs", "AboutUs", R.drawable.icon));
            tabHost.addTab(createTab(ExtraInfromation.class, 
                    "Extra", "Extra", R.drawable.icon));


            tabHost.setCurrentTab(0);
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
            tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
            tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
            tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;        
        }
        private TabSpec createTab(final Class<?> intentClass, final String tag, 
                final String title, final int drawable)
        {
            final Intent intent = new Intent().setClass(this, intentClass);

            final View tab = LayoutInflater.from(getTabHost().getContext()).
                inflate(R.layout.tab, null);
            ((TextView)tab.findViewById(R.id.tab_text)).setText(title);
            ((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);

            return getTabHost().newTabSpec(tag).setIndicator(tab).setContent(intent);
        }
    }

This is complete working code :Pragna

千仐 2024-11-21 12:48:28
<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@android:id/tabhost"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">

    <LinearLayout   android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

       <FrameLayout     android:id="@android:id/tabcontent"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

        <TabWidget      android:id="@android:id/tabs"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="0dip"/>

    </LinearLayout>

</TabHost>

Use this it will give you look that u r intersted
<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@android:id/tabhost"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">

    <LinearLayout   android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

       <FrameLayout     android:id="@android:id/tabcontent"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

        <TabWidget      android:id="@android:id/tabs"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="0dip"/>

    </LinearLayout>

</TabHost>

Use this it will give you look that u r intersted
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文