Align TextViews relative to each other

后端 未结 3 435
旧巷少年郎
旧巷少年郎 2021-01-27 08:43

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 f

相关标签:
3条回答
  • 2021-01-27 09:30

    You can add a LinearLayout with orientation: "horizontal" and add both textviews in it.

    <LinearLayout
         ...
         android:orientation="horizontal">
       <TextView .../>
       <TextView .../>
    </LinearLayout>
    
    0 讨论(0)
  • 2021-01-27 09:32

    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>
    
    0 讨论(0)
  • 2021-01-27 09:39

    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>
    

    OUTPUT

    OUTPUT WITH BIG TEXT

    0 讨论(0)
提交回复
热议问题