I have a tablerow in which i put in a textview with width==50dp;But when i add another tablerow which contains a textview with width==100dp,then the first textview has to be stretched to 100dp.
How can keep the width of the first textview's width?
Use android:stretchColumns properties .
To Know more Check out Link
You can also try this in layout for both textviews:
android:layout_width="0dp"
android:layout_weight="1"
This will give equal width to both the rows.
Related
I want to know how to automatically adjust the size of the TextView according to the length of the String. I am getting some data from another Intent as a String and storing it in a TextView. If I leave it small, the whole text won't fit and only half of it is displayed. If I leave a big space for the TextView it does not look nice on the screen.
The solution I found online was using extends TextView and using this method gives errors in my class and I have to change a lot of functions because of this
Use a multi-line TextView and set layout_height to wrap_content:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>
Note: If you set layout_width to wrap_content it won't work properly. If you don't want the TextView to take up the entire width of the parent view then either:
Set it to a fixed width in XML, or
Set the width programmatically, or
Set layout_alignLeft/layout_alignRight etc in a RelativeLayout
Set the layout_width to 0dp and use a layout_weight in a LinearLayout
If you are using xml file, just do this,
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>
And if you want to do dynamically do like this,
TextView textView= new TextView(activity);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(param);
how can i mange Textview in layout.? please help me..
how can i set textview and border then again textview.
Just create a horizontal LinearLayout, and add an ImageView, a TextView, a View with width 2dp and height match_parent, and a TextView as children.
Either repeat that for every row, or use the recommended approach of using a ListView with the above mentioned layout as rows.
I'd use two compound TextViews: Just create a horizontal LinearLayout, and add a TextView with drawableLeft="#drawable/icon_location" and another one with drawableLeft="#drawable/line_vertical" as children.
For both, a drawablePadding="8dp" or whatever you like best
I want to show a table row with three columns (TextView) but i want to divide the table row in three equal parts.
This is easily possible by setting a layoutWeightSum in TableRow in XML and making layout_weight=1 for all theww TextView.
But i adding the table at run time through java and not by xml.
All i know is the TableRow.LayoutParameter do not provide any thing for weightSum. How can i do this?
TableRow.LayoutParams pmRow = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
You can achieve this by following code.
TableLayout layout = //...findViewbyid
layout.setStretchAllColumns(true);
And make width 0dp to all the children (views) of TableRow like below.
<TextView
android:id="#+id/txt_no1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="hi" />
Note
Above is XML layout design, but you can create run time code also. Its just for demonstration.
I've got you covered, mate!
myTableRow.setWeightSum(float weightSum);
use pmRow.span=int value
like pmRow.span=3;
Create a LinearLayout xml (horizontal) with the three required Items ( TextViews). To add the row item at runtime, inflate the above said layout, and set text values and add it.
In my application i am creating and displaying a table at runtime. The table is developed in an Activity class. Everything working fine, only issue is the view of the table. There are four textviews in a row in the table. they are shown adjacently without seperation. How could i make a proper view with a definite space between textviews.
text1.setText("24/02/2011"); //TextView text
text2.setText("Andy"); //TextView text
text3.setText("3"); //TextView text
text4.setText("Repeat"); //TextView text
tableRow.addView(text1); //TableRow tableRow
tableRow.addView(text2); //TableRow tableRow
tableRow.addView(text3); //TableRow tableRow
tableRow.addView(text4); //TableRow tableRow
dueTL.addView(tableRow); //TableLayout dueTL
It display the data like : 24/02/2011Andy3Repeat
You can add weight to each TextView, also be sure that your TableView has fill_parent in its width. Also check the padding and margins of the TextViews
I hope this helps
If for some reason setting weights doesn't work for your situation, take a look at padding, paddingBottom, paddingLeft, paddingRight, and paddingTop in http://developer.android.com/reference/android/widget/TextView.html
You could either manually add a space to the strings in "setText" or you could set a right margin, if the surrounding ViewGroup supports it, on the TextViews either in XML (layout_marginRight) or via Code (LayoutParams).
I am implementing a table layout and adding table rows to it dynamically. I want give space between these rows. may I know how to do it. I am also adding a textView to the tableRow. I am declaring the table layout in the xml file. I tried giving padding inside the table row. But that seems to work within the tableRows and not between tableRows. please help.
You need to set the top or bottom margin of rows.
Here is an example: Programmatically set margin for TableRow
To set the margin between rows in a table layout you need to use the following XML
<Tablelayout> android:stretchColumns="*" </Tablelayout >