How to set scrollable text view in a TableRow - android

I have a textview wrapped in a table row.
The contents of the Textview may take up multiple lines so I am want to make the textview scrollable but with no success.
I have tried via XML and programmatically:
<TableRow
android:id="#+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_Refeeral_Center"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="#+id/tvTable_Referral_Center_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
android:maxLines="2"
android:scrollbars = "vertical"
android:typeface="sans"
android:ems="10"
android:hint="Hours "
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
And in my class I set the movement method of the textview:
referralLabTV.setMovementMethod(ScrollingMovementMethod.getInstance());
I have also tried by wrapping the textview in a scrollview but also does not work:
<TableRow
android:id="#+id/tableRow6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_RefRanges"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Ref Ranges"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
>
<TextView
android:id="#+id/tvrefRanges_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:maxLines="6"
android:typeface="sans"
android:ems="10"
android:hint="Ref Range"
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>
</TableRow>
Any input appreciated.
#Shagar
I tried your solution but still the same, can olnlt see first line of text that is added from database to the textview programmatically. This is the entire Linear/table layout
TableLayout
android:id="#+id/testSelcted_tabl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_selectedTest_Section2"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:shrinkColumns="1"
>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_TAT"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="TAT (hrs)"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="#+id/tvTable_TATText"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
android:maxLines="2"
android:scrollbars = "vertical"
android:typeface="sans"
android:ems="10"
android:text="Contact Referral Lab"
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_Fixation"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Fixation"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="#+id/tvTFixation_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
android:typeface="sans"
android:ems="10"
android:hint="Histology"
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_TATUrgent"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Urgent"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="#+id/tvTable_TATUrgetInput"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
android:typeface="sans"
android:ems="10"
android:hint="Hours "
android:padding="5dp"
android:textColor="#c4c4c4"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_Refeeral_Center"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Referral Lab"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="#+id/tvTable_Referral_Center_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
android:maxLines="2"
android:scrollbars = "vertical"
android:typeface="sans"
android:ems="10"
android:hint="Hours "
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="#+id/tvTable_RefRanges"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Ref Ranges"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<!-- wrap a linear layout in a scroll voew which wraps the textview fro textview to scroll -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#drawable/cell_shaoe"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvrefRanges_Input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="1"
android:typeface="sans"
android:ems="10"
android:hint="Ref Range"
android:textColor="#c4c4c4"
android:padding="5dp"
android:text="jwwhegfrhegihsighhgishgifhwihgawihrgaiwhgihigheihgraiehrgiher"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</TableRow>
</TableLayout>

Simply put a LinearLayout inside of your ScrollView.
and make your TextView height witdh matched to its parent.
here is the modified code.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#android:color/holo_blue_light"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvrefRanges_Input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="6"
android:typeface="sans"
android:ems="10"
android:hint="Ref Range"
android:textColor="#c4c4c4"
android:padding="5dp"
android:text="Hello\nHello\nHello\nHello\nHello\nHello\nHello\n"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>

The only way I could do this is change textview to a editview with attributes:
android:editable="false"
android:cursorVisible="false"

Related

TableLayout doesn't fit the screen

I am a beginner and I have designed a layout that displays the rows from the XML upon the click of a "show" Button.
But when I don't click the show button, I want the table row with id-blank to increase its height to fit the screen.
Please suggest a way to do that.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Row 1 with single column -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:gravity="center_horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Sale Report"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Row 2 with 3 columns -->
<LinearLayout
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/borders"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<EditText
android:id="#+id/starttime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:inputType="none"
android:textSize="#dimen/textSize" />
<EditText
android:id="#+id/stoptime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:inputType="none"
android:textSize="#dimen/textSize" />
<Button
android:id="#+id/show"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight=".75"
android:text="show" />
<Button
android:id="#+id/back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight=".75"
android:text="back" />
</LinearLayout>
<!-- Row 3 with 2 columns -->
<TableLayout
android:id="#+id/sale_table_data"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:background="#drawable/borders"
android:gravity="center" >
<TableRow
android:id="#+id/sale_report_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/Yellow" >
<TextView
android:id="#+id/particulars"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="Particulars"
android:textStyle="bold" />
<TextView
android:id="#+id/voucherNo"
android:layout_weight="1"
android:gravity="fill_horizontal"
android:text="VCH No"
android:textStyle="bold" />
<TextView
android:id="#+id/quantity"
android:layout_weight="1"
android:gravity="fill_horizontal"
android:text="Quantity"
android:textStyle="bold" />
<TextView
android:id="#+id/amount"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="Amount"
android:textStyle="bold" />
<TextView
android:id="#+id/date"
android:layout_weight="1.3"
android:gravity="center_horizontal"
android:text="Date"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/blank"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3" >
<TextView
android:id="#+id/blank9"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="Particulars"
android:textStyle="bold" />
<TextView
android:id="#+id/blank10"
android:layout_weight="1"
android:gravity="fill_horizontal"
android:text="VCH No"
android:textStyle="bold" />
<TextView
android:id="#+id/blank11"
android:layout_weight="1"
android:gravity="fill_horizontal"
android:text="Quantity"
android:textStyle="bold" />
<TextView
android:id="#+id/blank12"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="Amount"
android:textStyle="bold" />
<TextView
android:id="#+id/blank13"
android:layout_weight="1.3"
android:gravity="center_horizontal"
android:text="Date"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/no_borders" >
<TextView
android:id="#+id/blank1"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textStyle="bold" />
<TextView
android:id="#+id/blank2"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textStyle="bold" />
<TextView
android:id="#+id/Total"
android:layout_weight="1"
android:gravity="center"
android:text="Total"
android:textStyle="bold" />
<TextView
android:id="#+id/total_sales"
android:layout_weight="2"
android:gravity="center_horizontal"
android:text="Amount_value"
android:textStyle="bold" />
<TextView
android:id="#+id/blank3"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</ScrollView>

need buttons to spread out dynamically according to screen width

I am working on an app that originally had it's button layout configured statically. What happens now is that on wider screens (SIII, Note, Tablets etc.) the table layout remains the same size on all of them and doesn't "spead out" dynamically. How can this code be adjusted to accomplish this?
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:gravity="center_vertical"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" >
<RelativeLayout
android:id="#+id/stoolRelative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15px"
android:gravity="center_horizontal" >
<ImageButton
android:id="#+id/stoolmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menustool" >
</ImageButton>
<TextView
android:id="#+id/stoolText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/stoolmenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:text="#string/stoolmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/foodRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px"
android:gravity="center_horizontal" >
<ImageButton
android:id="#+id/foodmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menufood" >
</ImageButton>
<TextView
android:id="#+id/foodText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/foodmenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:text="#string/foodmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/PainRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px" >
<ImageButton
android:id="#+id/painmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menupain" >
</ImageButton>
<TextView
android:id="#+id/painText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/painmenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:text="#string/painmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15px"
android:gravity="center_horizontal" >
<RelativeLayout
android:id="#+id/moodRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px" >
<ImageButton
android:id="#+id/moodmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menumood" >
</ImageButton>
<TextView
android:id="#+id/moodText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/moodmenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:text="#string/moodmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/medsTakeRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px"
android:gravity="center_horizontal" >
<ImageButton
android:id="#+id/medstakemenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menumeds" >
</ImageButton>
<TextView
android:id="#+id/medsTakeText"
android:layout_width="70px"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/medstakemenu"
android:layout_alignRight="#+id/medstakemenu"
android:layout_below="#+id/medstakemenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:lines="2"
android:maxLines="2"
android:minLines="2"
android:singleLine="false"
android:text="#string/medstakenmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/otherIssuesRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px" >
<ImageButton
android:id="#+id/othermenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menuother" >
</ImageButton>
<TextView
android:id="#+id/otherIssuesText"
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_below="#+id/othermenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:lines="2"
android:maxLines="2"
android:minLines="2"
android:singleLine="false"
android:text="#string/otherissuesmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15px"
android:gravity="center_horizontal" >
<RelativeLayout
android:id="#+id/historyRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px" >
<ImageButton
android:id="#+id/historymenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menuhistory" >
</ImageButton>
<TextView
android:id="#+id/historyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/historymenu"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_marginTop="5px"
android:text="#string/historymenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/historyRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px"
android:gravity="center_horizontal" >
<ImageButton
android:id="#+id/academymenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menuacademy" >
</ImageButton>
<TextView
android:id="#+id/academyText"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_below="#+id/academymenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:lines="2"
android:maxLines="2"
android:minLines="2"
android:singleLine="false"
android:text="#string/ibdacademymenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/myPassPortRelative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15px"
android:gravity="center_horizontal" >
<ImageButton
android:id="#+id/mypassportmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="#drawable/menupassport" >
</ImageButton>
<TextView
android:id="#+id/myPassportTextUp"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#+id/mypassportmenu"
android:layout_centerHorizontal="true"
android:layout_marginTop="5px"
android:gravity="center_horizontal"
android:lines="2"
android:maxLines="2"
android:minLines="2"
android:singleLine="false"
android:text="#string/myibdpassportmenu"
android:textSize="11dp"
android:textStyle="bold" >
</TextView>
<!--
<TextView
android:layout_below="#+id/myPassportTextUp"
android:text="Passport" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/myPassportTextDown"
></TextView>
-->
</RelativeLayout>
</TableRow>
</TableLayout>
EDIT: Here is a screenshot of the current layout
As the screen gets wider, the table remains this exact size and the margin on either side increases. ideas?
For each TableRow change/add
android:layout_weight="1"
android:gravity="center_vertical"
For each RelativeLayout change/add
android:layout_weight="1"
You need to dynamically(programmatically) adjust the positioning of your layout elements. For example, if we have 2 TextViews inside a LinearLayout, we can add a OnGlobalLayoutListener to the LinearLayout:
myLinearLayout.getViewTreeObserver().addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener)
Inside this listener, we can access the width and the height of the layout elements. So, if we need to position our TextViews (spread them equally across the screen-width), we'll do the following:
int width = myLinearLayout.getWidth();
int lMarginTextView = (width - myTextView1.getWidth() - myTextView2.getWidth()) / 3;
LinearLayout.LayoutParams paramsTV = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
paramsTV.leftMargin = lMarginTextView;
myTextView1.setLayoutParams(paramsTV);
myTextView2.setLayoutParams(paramsTV);

Android table layout with textviews

I have my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearlayout01"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="52dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/Btn"
android:background="#drawable/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-2dp"
android:layout_marginTop="10dp">
</Button>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="1"
android:stretchColumns="0"
android:layout_marginTop="15dp" >
<TableRow android:weightSum="2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text="#string/HostName"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="0"
android:textColor="#000000"
android:textStyle="bold" />
</TableRow>
<TableRow android:weightSum="2"
android:layout_marginTop="30dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text="#string/programname"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:id="#+id/programname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
android:textColor="#000000"
android:textStyle="bold" />
</TableRow>
<TableRow android:weightSum="2"
android:layout_marginTop="30dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text="#string/Date"
android:textColor="#000000"
android:textStyle="bold" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0"
android:textColor="#000000"
android:textStyle="bold" />
</TableRow>
<TableRow android:layout_marginTop="20dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/mainlayout"
android:layout_marginLeft="-260dp"
android:layout_marginRight="0dp"
android:layout_marginTop="8dp" />
</TableRow>
</TableLayout>
</LinearLayout>
and I got the following output:
Update:
But my required output should be:
| HostName: text123 |
| PName: text3 |
| Date: text6 |
Could any one help?
String, try with this. I have attached the output too. I don't get any irregular text-alignments as I have shown in the below pic.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearlayout01"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="52dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-2dp"
android:layout_marginTop="10dp"
android:text="close">
</Button>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_marginTop="15dp" >
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:weightSum="2">
<TextView
android:id="#+id/TextView04"
android:text="Date"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
<TextView
android:id="#+id/TextView04"
android:text="text123"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:weightSum="2">
<TextView
android:id="#+id/TextView04"
android:text="Date"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
<TextView
android:id="#+id/TextView04"
android:text="text123"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:weightSum="2">
<TextView
android:id="#+id/TextView04"
android:text="Date"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
<TextView
android:id="#+id/TextView04"
android:text="text123"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:weightSum="2">
<TextView
android:id="#+id/TextView04"
android:text="Date"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
<TextView
android:id="#+id/TextView04"
android:text="text123"
android:textStyle="bold"
android:layout_width="0dp"
android:layout_weight="1"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/mainlayout"
android:layout_marginLeft="-260dp"
android:layout_marginRight="0dp"
android:layout_marginTop="8dp" />
</TableRow>
</TableLayout>
</LinearLayout>
Output:
Post back if you have any issues.
Better try this ..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/rows"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="#+id/key"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<TableRow
android:id="#+id/row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="HName" />
<TextView
android:id="#+id/txt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="HostName" />
</TableRow>
<TableRow
android:id="#+id/row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<TextView
android:id="#+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="PName" />
<TextView
android:id="#+id/txt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ProgramName" />
</TableRow>
<TableRow
android:id="#+id/row3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<TextView
android:id="#+id/txt5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date" />
<TextView
android:id="#+id/txt6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Todays Date" />
</TableRow>
</TableLayout>
</LinearLayout>
</RelativeLayout>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:weightSum="2" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text="Date"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="#+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="text123"
android:textColor="#ffffff"
android:textStyle="bold" />
</TableRow>
You must give android:layout_weight for both TextView in a TableRow equally . I think it will solve your issue
EDIT :
I just give simple modifications in your xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearlayout01"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="52dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/Btn"
android:background="#drawable/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-2dp"
android:layout_marginTop="10dp">
</Button>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="1"
android:stretchColumns="0"
android:layout_marginTop="15dp" >
<TableRow android:weightSum="2" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text="HostName"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
android:text="HostName"
android:textColor="#ffffff"
android:textStyle="bold" />
</TableRow>
<TableRow android:weightSum="2"
android:layout_marginTop="30dp"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text=" programname"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=" programname"
android:layout_weight="1"
android:textColor="#ffffff"
android:textStyle="bold" />
</TableRow>
<TableRow android:weightSum="2"
android:layout_marginTop="30dp"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:text=" Date"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=" date"
android:layout_weight="1"
android:textColor="#ffffff"
android:textStyle="bold" />
</TableRow>
<TableRow android:layout_marginTop="20dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/mainlayout"
android:layout_marginLeft="-260dp"
android:layout_marginRight="0dp"
android:layout_marginTop="8dp" />
</TableRow>
</TableLayout>
</LinearLayout>
Screen shot after my modification
Is this you want ??

How to increase width of particular EditText in Table Raw (Table layout)

I am using Table Layout.
Here i have three EditText's with same width ="200dp".
But i want to increase the size of 3rd EditText.
I made its width="wrap_content" but all other EditText also getting "wrap_content"
How can i increase the width of 3rd EditText with out affecting other EditText's.
This code for 3rd EditText:-
<TableRow
android:gravity="center_horizontal"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:id="#+id/addl"
android:text="Address"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:id="#+id/colon"
android:text=":" />
<EditText
android:layout_width="250dp"
android:layout_marginLeft="20dp"
android:id="#+id/et"
android:singleLine="true"/>
</TableRow>
Now i want to increase width of Address EditText only
i think you can achieve this by layout_weight parameter of EditTexts like below
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout12"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#909090"
android:padding="10dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student ID"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="6" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text=":"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
</TableLayout>
EDIT
This is the outcome
put the property android:stretchColumns="2" in TableLayout
<TableLayout android:stretchColumns="2" ... > .... </TableLayout>

how can i display text below listview in android?

I have an problem to displaying text below listview.when items are more in list the below text is not appear in my emulator. how can i solve this. i have use the below code.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg1"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TextView
android:id="#+id/t7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text=""
android:textColor="#000033"
android:typeface="serif" />
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/fromstation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#DC143C"
android:layout_gravity="left"
android:typeface="serif"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
android:textColor="#000000"
android:layout_gravity="center"
android:typeface="serif"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/tostation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#DC143C"
android:layout_gravity="right"
android:typeface="serif"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tname"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:padding="3dip"
android:text="Train"
android:layout_gravity="left"
android:textColor="#9400D3"
android:typeface="serif"
>
</TextView>
<TextView
android:id="#+id/arr"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:text="Arrival"
android:layout_gravity="center"
android:textColor="#9400D3"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/dep"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:text=" Departure"
android:textColor="#9400D3"
android:layout_gravity="right"
android:typeface="serif" >
</TextView>
</TableRow>
<ListView
android:id="#id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
>
</ListView>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/enq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*Marked services do not run on sunday."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#800000"
android:typeface="serif" />
</LinearLayout>
</TableLayout>
can anyone tell me where i have done wrong.
thanks in advance.
Try this, android:layout_weight="1" and change layout_height="match_parent" to android:layout_height="match_parent" inside lsitview and the below layoutview
<ListView
android:id="#id/android:list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:layout_weight="1">
</ListView>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/enq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*Marked services do not run on sunday."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#800000"
android:typeface="serif" />
</LinearLayout>
P.S. For make a space of listview lager than the below layout use Proportion of android:layout_weight to 1:3(Listview 1: the belowlayout 3) or any Propotion you want
Jusy give the listview height like
android:layout_height="100dp"

Categories

Resources