0

I would like to use a LinearLayout to position two TextViews' texts to the left in a single row . One TextView on the left hand side, the other on the right hand side. whole rows texts will be on the same line as vertically. Here is my XML:

   <?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:gravity="top|center"
    android:orientation="vertical"
    tools:context=".Butcegiris" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:ignore="UselessParent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@android:color/background_light"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textButtonBakici"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/textBakici" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:gravity="left"
                    android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textButtonBakici2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/textBakici" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textKrediAraba"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/textKrediAraba" />

                 <LinearLayout
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_gravity="left"
                     android:layout_weight="1"
                     android:gravity="left"
                     android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textKrediAraba2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/textKrediAraba" />
                </LinearLayout>
            </LinearLayout>

and its view;

enter image description here

vertically, numbers will be on the same line. thank you very much for your helps...

halfer
  • 19,824
  • 17
  • 99
  • 186
hopeTo
  • 223
  • 5
  • 15

2 Answers2

1

I think you should have a look at the TableLayout class. It should look much better.

Of course, if you think there would be a lot of items, consider using a listView with a constant width for each field.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
1

Your elements with layout_weight should have layout_width set to match_parent:

<?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:gravity="top|center"
    android:orientation="vertical"
    tools:context=".Butcegiris" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:ignore="UselessParent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@android:color/background_light"
            android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/textButtonBakici"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/textBakici" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:gravity="left"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textButtonBakici2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/textBakici" />
                </LinearLayout>        
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/textKrediAraba"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/textKrediAraba" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_weight="1"
                        android:gravity="left"
                        android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/textKrediAraba2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/textKrediAraba" />
                </LinearLayout>
            </LinearLayout>
Ljdawson
  • 12,091
  • 11
  • 45
  • 60