【问题标题】:How to create center raised tabbar?如何创建中心凸起的标签栏?
【发布时间】:2012-05-26 06:06:49
【问题描述】:

我想创建如下图所示的 TabBar:

这里,所有的标签栏都是正常的。只是它们是定制的。现在我想像上图一样创建标签栏。中间的 Tab 升起的位置。

那么我应该怎么做才能使它成为可能呢?

如果有demo就好了。

请帮帮我。

【问题讨论】:

  • 为 Android 重新设计你的应用,直接的 iPhone 端口很弱。
  • 你可以找到demo from this link
  • @Girish Bhutiya。感谢您的回答,但我已经解决了。
  • @iDroidExplorer 我需要做同样的标签栏你能告诉我我该怎么做。
  • @iDroidExplorer 你能帮我如何在标签栏标签的中心显示图像我面临这样做的困难

标签: android android-layout android-tabhost tabwidget


【解决方案1】:

您可以将 Tab 小部件中的背景图像设置为

tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.home_h);
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.live);
tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.camera);
tabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.profile);
tabHost.getTabWidget().getChildAt(4).setBackgroundResource(R.drawable.Messege);

将图像创建为其他四个,例如他们的前 20% 作为透明和中间相机创建为您的曲线基础。这样你就可以实现你的目标了。

像这样,灰色部分是透明部分。

【讨论】:

  • 是的,我见过你的图像,但它是方形图像。我想要我在问题帖子中的中心选项卡。
  • 无需更改中心图像,因为我显示只需要更改其他四个图像,如 HOME 图像。它将被设置,
  • hardik Gajjar:谢谢。让我试试。你的意思是我必须把其他图像的高度比中心图像低 20% 对吗??
  • 除四张图片外,所有图片的高度都相同 20% 顶部比例 使透明如上图所示。
  • 好的,我知道了。所以如果我想为它使用选择器,那么我还必须为新闻事件制作相同的图像吗?
【解决方案2】:

我正在做这样的事情:

<?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="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent" 
android:layout_height="match_parent">

    <TabWidget 
            android:id="@android:id/tabs" 
            android:layout_width="match_parent" 
            android:layout_height="0dp"
            android:tabStripEnabled="false"/>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/btn1" />

        <ImageView 
            android:id="@+id/btn1"        
            android:layout_alignParentBottom="true"      
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/btn2"
            android:src="@drawable/ic_launcher"/>

        <ImageView 
            android:id="@+id/btn2"
            android:layout_alignParentBottom="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/btn3"
            android:src="@drawable/ic_launcher"/>

         <ImageView 
            android:id="@+id/btn3"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/ic_launcher"/>     

         <ImageView 
            android:id="@+id/btn4"
            android:layout_toRightOf="@+id/btn3"
            android:layout_alignParentBottom="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"/>     

        <ImageView 
            android:id="@+id/btn5"
            android:layout_toRightOf="@+id/btn4"
            android:layout_alignParentBottom="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"/>                                         

</RelativeLayout>
</TabHost>

我摆脱了在 TabWidget 中的构建并通过 LinearLayout 设置我自己的。 稍后您只需要在主Tab Activity中设置onClick功能即可。

喜欢:

public void onClick(View v)
    {
            switch(v.getId())
            {
                    case R.id.btn1: 
                            tabHost.setCurrentTab(0);
                            break;
                    case R.id.btn2:
                            tabHost.setCurrentTab(1);
                            break;
                    case R.id.btn3:
                            tabHost.setCurrentTab(2);
                            break;
                    case R.id.btn4:
                            tabHost.setCurrentTab(3);
                            break;
                    case R.id.btn5:
                            tabHost.setCurrentTab(4);
                            break;
            }
    }    

【讨论】:

  • 感谢您的回答。但是中心选项卡呢?我想把它养成圆形。
  • 你正在使用RelativeLayout作为主要持有者。
  • 请您详细说明如何制作它?
  • 你不知道什么?你在哪里有问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-21
  • 1970-01-01
  • 2021-05-17
  • 2021-04-22
相关资源
最近更新 更多