在 Android 选项卡布局段落中创建分隔线
大家好,第一篇文章,虽然是 Android 编程菜鸟,但愿意学习!基本上,我从 此处
我发现该方法非常容易在每个选项卡中创建带有文本的选项卡,但我正在尝试这样做,以便在选择选项卡时,我希望下面列出的文本由分界线分隔。这样每个段落之间就有一条线分隔,但是我在这样做时遇到了困难。这是我到目前为止所拥有的: 主要.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中,我可以在第一行得到“这是第一个选项卡的第一行”,但是“这是第一个选项卡的第二行”显示在第一行行以及所有其他选项卡中。 预先感谢您的帮助,希望我所学到的知识将来可以帮助其他人。
Hey all, first post and a noob in Android programming, but willing to learn! Basically I've taken the Google sample of a tab layout from here
I found that method to be very easy to create tabs with text within each tab, but I'm trying to make it so that when a tab is selected, I want the text listed below to be separated by a dividing line. So that a line is dividing between each paragraph, however I'm having trouble doing this. This is what I have so far:
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>
Here is the info in the java file:
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);
}
}
In main.xml I can get "this is the FIRST line of the 1st tab" on the first line, but "this is the SECOND line of the 1st tab" is showing up in the first line, and in all other tabs.
Thanks in advance for any help, hopefully with my gained knowledge I can help others in the future.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只需要一个分隔符(将区域分为两部分的线),您可以在布局 XML 文件中使用以下代码;
上面的代码将生成一个 2dp 厚的海军蓝色分隔线。
增加
layout_height
将增加分隔线的厚度。恢复任何查询。
If you simply want a separator (line dividing the area into two sections), you can use the following code in your layout XML file;
The above code will produce a 2dp thick, navy blue divider.
Increasing the
layout_height
will increase the thickness of divider.Revert back for any query.