5

大家好,第一次发帖,是 Android 编程的菜鸟,但愿意学习!基本上我已经从这里获取了一个选项卡布局的谷歌样本

我发现该方法很容易在每个选项卡中创建带有文本的选项卡,但我正在尝试这样做,以便在选择选项卡时,我希望下面列出的文本用分隔线分隔。所以每段之间都有一条线,但是我在这样做时遇到了麻烦。这是我到目前为止所拥有的:main.xml:

<?xml version="1.0" encoding="utf-8"?>

        <TableRow>
            <TextView
            android:id="@+id/textview1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="this is the FIRST line of the 1st tab" />
            <TextView
            android:id="@+id/textview1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="this is the SECOND line of the 1st tab" />
            </TableRow>
            <View
    android:layout_height="2dip"
    android:background="#FF909090" />

    <TableRow>
        <TextView 
            android:id="@+id/textview2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="this is First line of the 2nd tab" />
            </TableRow>
            <View
    android:layout_height="2dip"
    android:background="#FF909090" />
            <View
    android:layout_height="2dip"
    android:background="#FF909090" /> 
         <TextView 
            android:id="@+id/textview3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="this is the First line of the 3rd tab" />
         <TextView 
            android:id="@+id/textview4"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="This is the First line of the 4th tab." />

            </TableLayout>
     </FrameLayout>

这是java文件中的信息:

  public class HelloTabWidget extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost mTabHost = getTabHost();

 mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));       
 mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
 mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
 mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("TAB 4").setContent(R.id.textview4));
        mTabHost.setCurrentTab(0);
    }
}

在 main.xml 中,我可以在第一行得到“这是第一个选项卡的第一行”,但“这是第一个选项卡的第二行”显示在第一行和所有其他选项卡中。在此先感谢您的帮助,希望凭借我所获得的知识,我将来可以帮助其他人。

4

1 回答 1

23

如果您只是想要一个分隔符(将区域分成两部分的线),您可以在布局 XML 文件中使用以下代码;

<View   android:id="@+id/firstDivider"
        android:layout_height="2dp"
        android:layout_width="fill_parent"
        android:background="#000080" />

上面的代码将生成一个 2dp 厚的深蓝色分隔线。增加layout_height将增加分隔线的厚度。

恢复任何查询。

于 2011-01-03T08:38:25.743 回答