0

there is code below. I need align textview to textview. The firsts one with id:test1 is very long with many lines and the second textview should be align to the first one test1 to the end of it. Any help?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/standard_margin"
    android:orientation="vertical">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/test1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:text="VERY LONG STRING HERE"
            android:textSize="@dimen/text_size_form"/>
        <TextView
            android:id="@+id/test2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="123"
            android:textSize="@dimen/text_size_form"/>
    </LinearLayout>
    <TextView
        android:id="@+id/abc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/text_size_form"/>
    <TextView
        android:id="@+id/abc1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/text_size_form"/>
</LinearLayout>
2
  • align mean start test2 when test1 is finished. One next one Commented Jun 18, 2015 at 15:14
  • Why dont you use relative layout with test2 textview align to test1 textview with android:layout_toRightOf. Commented Jun 18, 2015 at 15:28

1 Answer 1

1

You would need to make them expand to touch.

Use layout_weight on both.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/standard_margin"
    android:orientation="vertical">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/test1"
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:text="VERY LONG STRING HERE"
            android:textSize="@dimen/text_size_form"/>
        <TextView
            android:id="@+id/test2"
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:text="123"
            android:textSize="@dimen/text_size_form"/>
    </LinearLayout>
    <TextView
        android:id="@+id/abc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/text_size_form"/>
    <TextView
        android:id="@+id/abc1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/text_size_form"/>
</LinearLayout>

layout_width of 0dp with layout_weight of 0.5 (out of 1) means "i do not provide a width, expand it until it reaches 50%.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.