dimens file in values-sw360dp clashes with nexus4

2019-06-03 15:29发布

问题:

Creating an application in portrait mode where I have to align Button on image based on top margin. I'm using dimens file in values-sw360dp which is looking proper in nexus 5 but the same values is not aligning the Buttons in nexus 4 as both of the devices using values-sw360dp folder for dimens file.

Can you please suggest the solution for this. Also can any one provide list of all possible values folder that should be integrated to support multiple screens

Following is the code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/windowBackground">


    <ImageView
        android:id="@+id/bc_logo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitStart"
        android:src="@drawable/bc_imgbc_logo" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bc_logo"
        android:orientation="horizontal"
        android:weightSum="1"
        android:layout_alignParentTop="true"
        android:layout_marginTop="@dimen/bc_img_margin_top">

        <Button
            android:id="@+id/login_btn"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:background="@drawable/signing_tab_btn"
            android:text="SIGN IN"
            android:textColor="@color/colorAccent" />

        <Button

            android:id="@+id/registration_btn"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:text="REGISTER"
            android:textColor="#FFFFFF" />


    </LinearLayout>
</RelativeLayout

In above code I need to align the LinearLayout on the ImageView so using android:layout_marginTop="@dimen/bc_img_margin_top"for setting margin.

I have the Image in <ImageView/> which i have to give height and width as match parent in order to maintain aspect ratio and occupy width of screen so this results in the image showing in the area i wanted top of screen but the <ImageView/> is occupying area of whole screen and I want to align the <LinearLayout/> having buttons on the bottom part of Image.

Following is the image in which the sign in button with yellow underline and register button in white text needs to be aligned on bottom most part of the image where image ends. and the blue area depicts the area occupied by which covers the whole device height.

回答1:

you need to add some values by yourself like backgrounds and dimensions...


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00FF00">


    <ImageView
        android:id="@+id/bc_logo"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:scaleType="fitXY"
        android:src="@drawable/background" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="200dp"
        android:orientation="horizontal"
        android:layout_gravity="top"
        android:weightSum="1"

        >

        <Button
            android:id="@+id/login_btn"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"

            android:text="SIGN IN"
            android:textColor="#00FFFF" />

        <Button

            android:id="@+id/registration_btn"

            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:text="REGISTER"
            android:textColor="#00FFFF" />


</LinearLayout>
</FrameLayout>


回答2:

Create this kind of value structre for different sizes