在Android选项卡布局段落中创建分割线

4
嘿,大家好,这是我的第一篇帖子,我是一个Android编程的新手,但我很愿意学习!基本上,我已经采用了Google的选项卡布局示例,来自这里
我发现这种方法非常容易创建带有每个选项卡内文本的选项卡,但我正在尝试使选中选项卡时,下面列出的文本通过分隔线分开。这样每个段落之间都有一条线,但我遇到了麻烦。这是我目前为止的代码: 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中,我可以在第一行得到“这是第1个选项卡的第一行”,但是“这是第1个选项卡的第二行”显示在第一行,并且在所有其他选项卡中也是如此。 提前感谢任何帮助,希望通过我的所学知识来帮助他人。

1个回答

21

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

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

以上代码将生成一个2dp粗细的海军蓝色分隔线。 增加 layout_height 将增加分隔线的厚度。

有任何疑问请回复。


非常感谢您的快速回复,但是您提供的代码与我拥有的几乎相同。我要做的是在每个选项卡下面放置文本,在每个选项卡下面的文本中,我想用单独的段落,并在每个段落之间放一条线。到目前为止,我已经能够通过这样做将文本放在单独的段落中: <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="这是第一个选项卡的第一行\n这是第二个选项卡的第二行"/> - Clozecall
使用\n在每个制表符内创建一个新段落,但我想要更多的段落,并且通过每个段落之间划分一条线。-谢谢。 - Clozecall
@mudassir:我能通过Java代码创建分隔符吗?如果可以,怎么做?请尽快回复。 - Shruti
1
@Shruti:可以的。试试这个链接,http://stackoverflow.com/questions/15622711/linearlayout-programmatically-how-to-set-up-a-divider#15622754 - Mudassir
1
@Mudassir:感谢您的即时回复..这对我很有帮助。 - Shruti

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接