0

Im new with Android programming on Android Studio and this seems to be simple question.

In Swift I used to get screen WIDTH and HEIGHT to put all my widgets on screen position and resize them, which in my opinion is a nice way to do that.

Here I don't know how to do that. Ive made this screen here on XML file, this screen is the PREVIEW:

enter image description here

Ive set the buttons like this:

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

    <ImageView
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:alpha="0.7"
    android:src="@mipmap/imgbackgroundstartview"
    android:id="@+id/imgBackgroundStartView"
    android:layout_height="wrap_content"/>

    <ImageView
    android:layout_width="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@mipmap/btnstartcpr"
    android:id="@+id/imgStartViewStartVisible"
    android:layout_height="wrap_content"/>

    <ImageView
    android:layout_width="match_parent"
    android:layout_centerHorizontal="true"
    android:src="@mipmap/imgstartviewtitle"
    android:layout_marginTop="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginBottom="400dp"
    android:id="@+id/imgStartViewTitle"
    android:layout_height="wrap_content"/>

    <TextView
    android:layout_width="match_parent"
    android:layout_centerVertical="true"
    android:text="START"
    android:layout_centerInParent="true"
    android:gravity="center_horizontal"
    android:textColor="#ffffffff"
    android:textStyle="bold"
    android:fontFamily="sans-serif-medium"
    android:textSize="36dp"
    android:layout_height="wrap_content" />

    <Button
    android:layout_width="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="420dp"
    android:layout_marginRight="250dp"
    android:layout_marginBottom="20dp"
    android:id="@+id/btnLoginStartView"
    android:background="@mipmap/imgstartviewlogin"
    android:layout_height="wrap_content"/>

</RelativeLayout>

However when I run the program it has a different positioning and sizes:

enter image description here

So short question: how to do the same as I was doing on SWIFT, ie: Set button height as 10% of screen height; Set button width as 50% of screen width; Position button on point (width: 50% of screen width, height: 50% of screen height), which is middle of screen.

The answer could be programmatically or on XML file, both works for me. Thanks in advance!

0 Answers0