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