Reputation: 161
I have two TextView. First TextView contains dynamic text, that can be small and big. Second TextView contains static small text. Second TextView should be located to right of first TextView.
This is how it should works:
How can I make this layout? With Relative or Linear layouts when first TextView contains big text - second text simply disappeared from screen.
Upvotes: 0
Views: 139
Reputation: 69681
Try this FlexboxLayout
Add the following dependency to your build.gradle file:
dependencies {
compile 'com.google.android:flexbox:0.3.2'
}
Usage
<com.google.android.flexbox.FlexboxLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexWrap="nowrap"
app:alignItems="stretch"
app:alignContent="stretch" >
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0"
android:text="niledfdfdfhfgfdgdfgdfgfgfggdfgdfggggggggggggggggggggggggggggggggggggggggggggggfhssdsdsdsfgdfgfgfgfgfggfgdgdfgfgfgdsddjfhdkjfhjshdf" />
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:text="nilxcvxceshdfhd"
android:background="@color/colorAccent"
android:layout_height="wrap_content"
app:layout_minWidth="50dp"
app:layout_minHeight="20dp"
app:layout_alignSelf="center"
/>
</com.google.android.flexbox.FlexboxLayout>
Upvotes: 2
Reputation: 459
try this code I think It will work as you want
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/txt_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="asdasdadasdasdasdasdasdasdasdasdasdasdasdasd"/>
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:text="2asdasdadasdasdasdasdasdasdasdasdasdasdasdasd"
android:layout_height="wrap_content"/>
</LinearLayout>
Upvotes: 0
Reputation: 1805
You can add a LinearLayout with orientation: "horizontal" and add both textviews in it.
<LinearLayout
...
android:orientation="horizontal">
<TextView .../>
<TextView .../>
</LinearLayout>
Upvotes: 0