Reputation: 927
I have a horizontal linearLayout including a TextView, an EditText and another EditText. Both TextViews are set to wrap_content in width and heigth. The EditText has wrap_content in height and match_parent in width.
My goal is to get those three views in one line filling the whole line. But with the above written settings, I have the first TextView taking up the needed space and the EditText filling the rest, not keeping free space for the other TextView.
I achieved a temporary solution by setting layout_weight of both TextViews to 0 and of the EditText to 500 which I'm sure is not the real solution.
Edit: current layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutWeight"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gewicht:"
android:id="@+id/lblWeight"
android:layout_alignParentStart="true"
android:textColor="@color/mainForeground"
android:textSize="24dp"
android:layout_weight="1"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtWeight"
android:layout_alignBottom="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:textAlignment="center"
android:hint="60"
android:textSize="24dp"
android:textColor="@color/mainForeground"
android:textColorHint="@color/hintColor"
android:layout_weight="500"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblUnitWeight"
android:textColor="@color/mainForeground"
android:textSize="24dp"
android:layout_weight="1"
android:text="g." />
</LinearLayout>
Upvotes: 0
Views: 151
Reputation: 2558
You can use this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutWeight"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gewicht:"
android:id="@+id/lblWeight"
android:layout_alignParentStart="true"
android:textColor="@color/mainForeground"
android:textSize="24dp"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/txtWeight"
android:layout_alignBottom="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:textAlignment="center"
android:hint="60"
android:textSize="24dp"
android:textColor="@color/mainForeground"
android:textColorHint="@color/hintColor"
android:layout_weight="500"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblUnitWeight"
android:textColor="@color/mainForeground"
android:textSize="24dp"
android:text="g." />
</LinearLayout>
Upvotes: 0
Reputation: 209
I'm a little bit consufed, but is this what you want?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/leftTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/editText"
android:layout_toEndOf="@+id/leftTextView"
android:layout_toStartOf="@+id/rightTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content/>
<TextView
android:id="@+id/rightTextView"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Try this, it should works fine.
Upvotes: 1
Reputation: 6704
Use layout_weight to determine width of each views. Update the weight values according to your need.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutWeight"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Gewicht:"
android:id="@+id/lblWeight"
android:layout_alignParentStart="true"
android:textColor="@color/mainForeground"
android:textSize="24dp"
android:layout_weight="1"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:id="@+id/txtWeight"
android:layout_alignBottom="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:textAlignment="center"
android:hint="60"
android:textSize="24dp"
android:textColor="@color/mainForeground"
android:textColorHint="@color/hintColor"
android:layout_weight="500"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/lblUnitWeight"
android:textColor="@color/mainForeground"
android:textSize="24dp"
android:layout_weight="1"
android:text="g." />
</LinearLayout>
Upvotes: 1