Creating line dividers in Android tab layout paragraphs
If you simply want a separator (line dividing the area into two sections), you can use the following code in your layout XML file;
<View android:id="@+id/firstDivider"
android:layout_height="2dp"
android:layout_width="fill_parent"
android:background="#000080" />
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.
Related videos on Youtube
Clozecall
Updated on June 04, 2022Comments
-
Clozecall almost 2 years
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.
-
Clozecall over 13 yearsThanks for the very quick response, however the code you gave is almost the same thing that I have. What I'm trying to do is put text under each tab, the text under each tab I want in seperate paragraphs, and inbetween each paragraph I want a line going through. Thus far I was able to put the text in seperate paragraphs by doing this: <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 \nthis is the SECOND line of the 2st tab" />
-
Clozecall over 13 yearsUsing \n creates a new paragraph within each tab, but I want more than one paragraph, and a line divinding through each one. -Thanks.
-
Shruti almost 11 years@mudassir : can i create a divider through java code ? if yes then how ?? please reply its urgent
-
Mudassir almost 11 years@Shruti: Yes, you can. Try this, stackoverflow.com/questions/15622711/…
-
Shruti almost 11 years@Mudassir : thanks for the spontaneous response .. it helped me