When i add long text to my TextView in linear layout it takes up all the space, and other views get squeezed. I set layout_width="0" to every view but it did not help. I should also add that this layout is used in RecyclerView.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100">
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/lp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Lp"
android:layout_weight="5" />
//this TextView takes all the space if text is long, but it behaves normally if text is short
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/nazwa"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Końcówka Yankauer do odsysania pola operacyjnego CH 23 (4 otwory boczne) z kontrolą odsysania"
android:layout_weight="20"/>
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/ilosc"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="#"
android:layout_weight="5" />
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/jednostka"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="JM"
android:layout_weight="15" />
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/cenaNetto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="C. net."
android:layout_weight="15" />
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/wartNetto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="W.net."
android:layout_weight="15" />
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/wartVAT"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="VAT"
android:layout_weight="10" />
<TextView
android:textSize="12sp"
android:gravity="center"
android:id="#+id/wartBrutto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="W. brut."
android:layout_weight="15" />
</android.support.v7.widget.LinearLayoutCompat>
Here is a print screen of what breaks in my app link
Please try below link code as a demo I hope you will get your result.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/row_my_booking_unit_name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
</TextView>
<TextView
android:id="#+id/row_my_booking_unit_quantity"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
</TextView>
<TextView
android:id="#+id/row_my_booking_unit_amount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
</TextView>
</LinearLayout>
</TableRow>
</TableLayout>
Did you tried this in your TextView?
android:ellipsize="end"
android:maxLines="1"
If you want each textview to occupy same space then you can assign layout_weight=1 for all.
Related
Hi I'm learning Android.
Here is the code for my Layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context="com.example.android.aidsdruginformation.DetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
UI Screen shot:
How I want my UI to look:
Why is the second LinearLayout not showing?
Am I doing something wrong?
While using layout_width should the parent element have a fixed dimension?
Please advice..
Link to my Repo:
https://github.com/MukundPradeep/AidsDrugInformation
Going through my Repo,
I figured that the activity_detail.xml under the layout v-17 folder was being used by the framework because the android:textAlignment="center" attribute I have used is only available for API 17+. My target SDK is 23.
Therefore the layout I posted(under layout directory) would only show on devices running versions of Android less than 17.
If you are planning to use the above mentioned attribute, please make sure you implement your layout changes in all the layout folders generated for different APIs.
Thanks everyone for trying to help me out.
you can use android:fillViewport
Defines whether the scrollview should stretch its content to fill the
viewport.
Must be a boolean value, either "true" or "false".
You should try with below approach . make LinearLayout as root .
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
// Your Staff
</ScrollView>
</LinearLayout>
Try, added some attribute to ScrollView ,
android:fillViewport="true",
android:isScrollContainer="true"
add LinearLayout as parent of ScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:isScrollContainer="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:gravity="center"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8" />
</LinearLayout >
</ScrollView >
</LinearLayout >
I tried with your code and it is showing
try this way
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:fillViewport="true"
tools:context="com.example.android.aidsdruginformation.DetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
OUTPUT
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context="com.example.android.aidsdruginformation.DetailActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="FDA-approved"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="ApprovalStatus"
android:textAlignment="center" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:elevation="4dp"
android:padding="8dp"
android:text="GDA-approved"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
You are giving the first layout weight as 1. Which will take the full height of screen. You can divide it. But also inside scrollview if you give weight then what is the use of that scrollview.
check this .and make it as right if its helpful.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_weight="1"
android:id="#+id/l1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Now book a ride at 6Rs/km with uber go"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="7/11 supermarket get special discounts today only"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/l1"
android:padding="10dp"
android:layout_weight="1"
android:id="#+id/l2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="10% discount on all meals"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Clearance sale upto 40% off"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="201dp"
android:layout_below="#id/l2"
android:layout_weight="1"
android:padding="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Starbucks coffee try our special new mocha latte for a limited period discount"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:text="Buy 2 get 1 free*"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
Just give parent linear layout this attribute:
android:weightSum="2" then your both child linear layout are Shown on Screen.
Wrap your two linear layouts with another linear layout with vertical orientation(as shown in the many comments). In your case both the linear layouts are overlapping each other so you see just one.
Unless it has enough items to scroll, it can not be scrollable.
I was trying to make an interface that allows horizontal texts to be equally space, using layout_weight for responsiveness
So, I tried the code below
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="#android:color/darker_gray">
<TextView
android:gravity="center"
android:text="Guest List"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:background="#android:color/holo_blue_bright"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white">
<TextView
android:text="Kunal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="24sp"/>
<TextView
android:text="Darling"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="24sp"/>
<TextView
android:text="Shocker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="24sp"/>
</LinearLayout>
However, all the texts disappear.
So, could anyone please kindly explain to me what happened and how to fix this problem?
Try this,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_bright"
android:gravity="center"
android:text="Guest List"
android:textSize="24sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Kunal"
android:textSize="24sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Darling"
android:textSize="24sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Shocker"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
Using a white background color in the second LinearLayout, you may be trying to see white on white text.
I'd try to add to the TextViews something along:
android:textColor="#android:color/black"
I have a linearlayout and a textview inside another linearlayout. The linearlayout from inside is displayed, but the problem is that the last textview is not. Why?
<LinearLayout 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"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Scrie un cuvant" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<EditText
android:id="#+id/cuvant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/cuvant_hint"
android:inputType="text" />
<Button
android:id="#+id/cuvantbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cuvantbutton_text" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Sau random" />
</LinearLayout>
Have a look here,
Your LinearLayout has height-attribute fill_parent. Change to wrap_content.
You are actually telling LinearLayout to capture all available space, which is causing you last textview not showing. Instead use "wrap_content" which tells to capture space required to show the available content.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Scrie un cuvant" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<EditText
android:id="#+id/cuvant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/cuvant_hint"
android:inputType="text" />
<Button
android:id="#+id/cuvantbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cuvantbutton_text" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Sau random" />
</LinearLayout>
Check the layout_height of internal LinearLayout from match_parent to wrap_content
your innerLayout height is match_parent because of which your last textview was not visible
<LinearLayout 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"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Scrie un cuvant" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" <<---- Change it to wrap_Content from match_parent
android:gravity="center_horizontal"
android:orientation="horizontal" >
<EditText
android:id="#+id/cuvant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/cuvant_hint"
android:inputType="text" />
<Button
android:id="#+id/cuvantbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cuvantbutton_text" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Sau random" />
</LinearLayout>
The parent layout must cover the textview, to get text in it.
The layout with problem,which does not diplay text-----------
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/Crime">
</ImageView>
<LinearLayout
android:layout_width="330dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="God Father"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Crime Drama"
android:textSize="30dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
After changing the size of parent layout, which covers the textview.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/Crime">
</ImageView>
<LinearLayout
android:layout_width="330dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="God Father"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Crime Drama"
android:textSize="30dp"
android:textStyle="bold" />
</LinearLayout>
I thought this will be a common question, but I couldn't find any answers......
Is it possible to center-aligned a (variable length) textview based on a percentage of the screen width?
In my case, I have 2 textview and I want to achieve something like this:
Another example:
The first textview is center-aligend 30% of the screenwidth, width=wrap_content, while the second textview takes up the rest of the space. The first textview's size should NOT be fixed (see picture above)
I do not want to do that programatically, as it will be expensive on my program. If possible it's better be in an xml layout file :)
Right now I can only achieve a "left-aligned" textview using layout_weight of LinearLayout (by putting a 30% dummy on the left), but I want center-alignment.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="3" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="another textview"
android:textColor="#FFFF0000"/>
</LinearLayout>
</LinearLayout>
With almost an hour testing this "..." layout, I succeeded with this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="40"
android:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/left_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="0dp"
android:gravity="center"
android:padding="0dp"
android:singleLine="true"
android:text="first textview"
android:textColor="#FFFF0000" >
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#0000FF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#00FF00"
android:gravity="center"
android:text="textview"
android:textColor="#FFF" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/left_layout"
android:background="#0000FF"
android:gravity="center"
android:text="textview"
android:textColor="#FFF" />
</RelativeLayout>
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="60"
android:background="#FFFF0000"
android:gravity="right"
android:singleLine="true"
android:text="another textview"
android:textColor="#FFF" />
</LinearLayout>
Outputs
Finally in your Java, according to the green textview width or content length, you can change the layout_weight for other textviews programmatically.
This should help you
Have a nice day.
// try this way hope this will help you...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="0.15"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.85">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="first Textview"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="second textview demo text "/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
try this one
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Work perfect checked by me.
I tried to make a timetable app for my school for fun by using a TableLayout with TableRow with TextView in it. The problem is that when i enter a longer text the TextView moves down.
Here is my xml:
`
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:text="Mo"
android:background="#ffffff"
android:gravity="center"
android:layout_margin="1dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:gravity="center"
android:text="Tu"
android:background="#ffffff"
android:layout_margin="1dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:text="WeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWe"
android:gravity="center"
android:background="#ffffff"
android:layout_margin="1dp"
/>
</TableRow>
</TableLayout>`
and here is a picture of what it looks like
Upd for your layout type.
This seems works fine. Change your textColor and other parameters as you like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="#+id/tableRow"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_margin="1dp"
android:background="#ffffff"
android:text="Mo"
android:textColor="#color/colorPrimaryDark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_margin="1dp"
android:background="#ffffff"
android:text="Tu"
android:textColor="#color/colorPrimaryDark" />
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="1dp"
android:background="#ffffff"
android:gravity="center"
android:text="WeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWeWe"
android:textColor="#color/colorPrimaryDark" />
</TableRow>
</TableLayout>
</RelativeLayout>