简体   繁体   中英

how to set layout in multiple screen size in android

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="2">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/increment_5x"
            android:paddingLeft="@dimen/baseline_grid_7x"
            android:paddingRight="@dimen/baseline_grid_7x"
            android:paddingTop="@dimen/baseline_grid_7x">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/textView"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
            android:addOnPageChangeListener="@{landingLoginViewModel.pageChangeListener}"
                app:adapter="@{imageSlideradapter}"
                app:currentItem="@{landingLoginViewModel.currentPage}" />            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/indicator"
                android:fontFamily="sans-serif"
                android:gravity="center_horizontal"
                android:lineSpacingExtra="@dimen/text_land_spacing"
                android:paddingTop="@dimen/layout_padding_top"
                android:text="@string/label_businesscard_title"
                android:textColor="#3e4360"
                android:textSize="@dimen/businees_card_textmessage_size"
                android:textStyle="normal" />
                <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/indicator"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:paddingTop="@dimen/padding_top_15dp"
                app:centered="true"
                app:fillColor="@color/colorTurquoiseBlue"
                app:pageColor="@color/colorPager"
                app:radius="@{landingLoginViewModel.pagerIndicatorCircle}"
                app:snap="false" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/relativelayout_top_height_350_dp"
            android:paddingLeft="@dimen/baseline_grid_2.5x"
            android:paddingRight="@dimen/baseline_grid_2.5x"
            android:paddingTop="@dimen/baseline_grid_5x">

            <android.support.v7.widget.AppCompatButton
                android:id="@+id/btn_signin"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/buttonbackroudnd"
                android:onClick="@{()->landingLoginViewModel.onSignIn()}"
                android:text="@string/label_sign_in"
                android:textColor="#ffffff" />

            <android.support.v7.widget.AppCompatButton
                android:id="@+id/btn_signup"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/btn_signin"
                android:layout_marginTop="@dimen/baseline_grid_3.5x"
                android:background="@drawable/roundbuttonborder"
                android:onClick="@{()->landingLoginViewModel.onSignUp()}"
                android:text="@string/label_sign_up"
                android:textColor="#00becc" />

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/oRtextLabel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/btn_signup"
                android:layout_marginTop="@dimen/baseline_grid_5.5x"
                android:gravity="center"
                android:text="@string/label_or"
                android:textColor="@color/colorDarkGrey"
                style="@style/Regular.Body2"
                />
            <ImageView
                android:id="@+id/faceBookIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/fb_icon"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/oRtextLabel"
                android:layout_marginTop="@dimen/baseline_grid_5x"
                android:gravity="center"
                android:layout_marginLeft="75dp"
                />

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-medium"
                android:paddingLeft="@dimen/baseline_grid_1x"
                android:text="@string/label_fcebook"
                android:textColor="@color/facebookTextColor"
                android:textSize="@dimen/baseline_grid_2x"
                android:textStyle="normal"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/oRtextLabel"
                android:layout_toRightOf="@+id/faceBookIcon"
                android:layout_marginTop="@dimen/baseline_grid_5x"
                android:gravity="center"
                android:onClick="@{()->landingLoginViewModel.onFacebook()}"
                />


        </RelativeLayout>
    </LinearLayout>
</ScrollView>

this is my Screen size i have created folder for differnet screen size in valued folder the screen which i have is designed in xhdpi but i have to support in all screen without scrolling i tried with different size in value accrding this formula

mdpi=56/2=28dp hdpif=42dp xhdpi-56 dp xxhdpi=84dp xxxhdpi=112 dp

but this is not working still scrolling is there can any one please suggest me how to fix it how to set layout in all screen size

I think you should try to design 5 layouts for one screen and make sure if you don't want to give scroll then remove one from 5 layouts

1.mdpi: // suppose i am giving scroll for small devices

2.hdpi

3.xhdpi // up to this , i don't need scroll

4.xxhdpi

5.xxxhdpi

Note: resources and id , if you are using in main Activity keep same in all layouts otherwise you can get null pointer exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM