首页 > 解决方案 > 如何使用“adjustpan”选项将工具栏固定到活动顶部?

问题描述

我做了如下布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_below="@+id/layout_progress"
        android:layout_alignParentStart="true"
        android:layout_weight="1">

    </android.support.v7.widget.Toolbar>

    <ScrollView
        android:id="@+id/scroll_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayout12"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="?attr/actionBarSize"
        android:layout_weight="0"
        android:fillViewport="true">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/message_table"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        </android.support.v7.widget.RecyclerView>
    </ScrollView>

    <LinearLayout
        android:id="@+id/linearLayout12"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_above="@+id/linearLayout8"
        android:layout_alignParentLeft="true">

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/linearLayout8"
        android:layout_above="@+id/layout_inputfield"
        android:layout_alignParentLeft="true">

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_inputfield"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal">

            <LinearLayout
                android:id="@+id/linearLayout6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:gravity="center_vertical"
                android:orientation="horizontal">

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <ImageView
                            android:id="@+id/imageView19"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="0"
                            android:src="@drawable/test" />

                        <ImageView
                            android:id="@+id/imageView18"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:scaleType="fitXY"
                            android:src="@drawable/test2" />

                        <ImageView
                            android:id="@+id/imageView7"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="0"
                            android:src="@drawable/test3" />
                    </LinearLayout>

                    <EditText
                        android:id="@+id/edit_input"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:layout_weight="1"
                        android:background="@android:color/transparent"
                        android:ems="10"
                        android:inputType="textMultiLine"
                        android:textColor="@android:color/black">

                        <requestFocus />
                    </EditText>
                </RelativeLayout>

            </LinearLayout>

        </RelativeLayout>
    </LinearLayout>


</RelativeLayout>

问题是上传键盘时UI被剪切。

所以我用 [adjustpan] 选项解决了它。

这与我预期的结果相同。

但我什至看不到“工具栏”。

我总是想在顶部显示“工具栏”。

1

2

我会更容易地将图像附加到当前情况。

如果您需要任何信息,请告诉我。

标签: androidlayoutadjustpan

解决方案


推荐阅读