布局上方

时间:2018-09-04 15:45:24

标签: java android layout

我正在尝试在Android应用程序中创建此页面:

enter image description here

现在,我最终使用以下布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="48dp"
                android:text="My App"
                android:textAlignment="center"
                android:textColor="@android:color/white"
                android:textSize="36sp"
                android:textStyle="bold|italic"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:orientation="vertical">

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical">

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="24dp"
                android:elevation="10dp"
                app:cardCornerRadius="16dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:padding="24dp">

                    <android.support.design.widget.TextInputLayout
                         android:id="@+id/default_text_layout"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent">

                     <android.support.design.widget.TextInputEditText
                         android:id="@+id/default_text"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:singleLine="true"
                         android:theme="@style/AppTheme" />
                     </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                         android:id="@+id/default_text_layout"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent">

                     <android.support.design.widget.TextInputEditText
                         android:id="@+id/default_text"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:singleLine="true"
                         android:theme="@style/AppTheme" />
                     </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                         android:id="@+id/default_text_layout"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent">

                     <android.support.design.widget.TextInputEditText
                         android:id="@+id/default_text"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:singleLine="true"
                         android:theme="@style/AppTheme" />
                     </android.support.design.widget.TextInputLayout>


                </LinearLayout>
            </android.support.v7.widget.CardView>
        </LinearLayout>

    </LinearLayout>

</FrameLayout>

结果是这样的:

enter image description here

问题是当键盘对准焦点时,我得到了这个结果,将AdjustResize放在清单中:

enter image description here

你知道吗:

1)避免在键盘对准焦点时遮盖输入 2)像第一个图形一样放置按钮(在底部边缘上方)

如果您对如何改进xml有任何建议,那将是不错的选择,因为我是android xml的新手。

提前谢谢

1 个答案:

答案 0 :(得分:0)

1)如果清单中没有adjustSize,我没有任何问题 screenshot

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textView6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="48dp"
                android:text="My App"
                android:textAlignment="center"
                android:textColor="@android:color/white"
                android:textSize="36sp"
                android:textStyle="bold|italic"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:orientation="vertical">

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical">

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="24dp"
                android:elevation="10dp"
                app:cardCornerRadius="16dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:padding="24dp">

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/default_text_layout1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/default_text1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:theme="@style/AppTheme" />
                    </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/default_text_layout2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/default_text2"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:theme="@style/AppTheme" />
                    </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/default_text_layout3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/default_text3"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:theme="@style/AppTheme" />
                    </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/default_text_layout4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/default_text4"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:theme="@style/AppTheme" />
                    </android.support.design.widget.TextInputLayout>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/default_text_layout5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/default_text5"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:theme="@style/AppTheme" />
                    </android.support.design.widget.TextInputLayout>

                </LinearLayout>
            </android.support.v7.widget.CardView>
        </LinearLayout>

    </LinearLayout>

</FrameLayout>

2)尝试使用ConstraintLayoutdocs)创建平面布局,而不是分层布局(这对于提高您的应用性能)

相关问题