Text image on the left side with a button on the right side without absolute values

I'm trying to get text to hug the left side of the screen, while the button hugs the right side (and if possible only for ocd, the radius of the center of the text will be vertical to be consistent with the button), but don't do this using absolute values. Here is my coding:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Change City:"
/>
<Button 
android:layout_width="100px" 
android:layout_height="wrap_content" 
android:layout_gravity="right"
android:text="Click" 
android:id="@+id/citychoicebutton"
/>
</LinearLayout>

I thought layout_gravity would take care of what I was trying to do, but apparently not.

+3
source share
2 answers

Gravity indicates how to place an element inside the element itself, and not in the boundaries of the parent (screen).

, 50 , 100 TextView, , 100 ( ).

LinearLayout , "dip" , ( ).

Relative Layout android: layout_alignParentLeft android: layout_alignParentRight.

, "dip" ( ), "px" .

, , "dp". "dip" .

+3

RelativeLayout

android:layout_alignParentLeft

TextView

android:layout_alignParentRight

. TextView,

android:layout_alignbaseLIne 

.

+2

Source: https://habr.com/ru/post/1758855/


All Articles