如何设置工具栏以适应活动在android中

时间:2017-06-26 11:05:42

标签: android layout android-toolbar

我正在尝试将工具栏添加到活动中,但如果我正在滚动它会滚动 以下是我试过的代码 我需要不滚动到工具栏只包含我想要滚动。我想像这个图像一样设计如何设计如下图像enter image description here

的形式
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:id="@+id/CoordinatorLayout_login"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:fillViewport="true"
        android:focusable="true"

        android:focusableInTouchMode="true"
        android:gravity="center"
        android:orientation="vertical">


        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbarforprofile"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"

                    android:background="?attr/colorPrimary"
                    android:minHeight="?attr/actionBarSize"
                    android:titleTextColor="#ffffff" />


                <LinearLayout
                    android:id="@+id/profile_details"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="30dp"
                    android:orientation="vertical"
                    android:padding="16dp">

                    <TextView
                        android:id="@+id/txtservicedetails"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"

                        android:gravity="center"
                        android:text="@string/app_name"
                        android:textColor="@color/colorAccent"
                        android:textSize="20sp"
                        android:textStyle="bold" />

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

                        <AutoCompleteTextView
                            android:id="@+id/editTextrequirement"
                            android:layout_width="match_parent"
                            android:layout_height="100dp"
                            android:hint="Your requirement?"
                            android:inputType="textMultiLine|textCapSentences"
                            android:maxLines="4"
                            android:singleLine="true"
                            android:text="" />

                    </android.support.design.widget.TextInputLayout>

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

                        <AutoCompleteTextView
                            android:id="@+id/et_dateofvisit"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"

                            android:focusable="false"
                            android:hint="Date Of Visit"
                            android:inputType="date"
                            android:maxLines="1"
                            android:singleLine="true"
                            android:text="" />

                    </android.support.design.widget.TextInputLayout>


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

                        <AutoCompleteTextView
                            android:id="@+id/et_time"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"

                            android:focusable="false"
                            android:hint="Time Of Visit"
                            android:inputType="time"
                            android:maxLines="1"
                            android:singleLine="true"
                            android:text="" />

                    </android.support.design.widget.TextInputLayout>


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

                        <AutoCompleteTextView
                            android:id="@+id/et_noofperson"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"

                            android:hint="Number Of Person You Need"
                            android:inputType="number"
                            android:maxLines="1"
                            android:singleLine="true"
                            android:text="" />

                    </android.support.design.widget.TextInputLayout>


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

                        <AutoCompleteTextView
                            android:id="@+id/et_serviceadd"
                            android:layout_width="match_parent"
                            android:layout_height="100dp"

                            android:hint="Service Address"
                            android:inputType="textMultiLine|textCapSentences"
                            android:maxLength="2000"
                            android:maxLines="4"
                            android:singleLine="true"
                            android:text="" />

                    </android.support.design.widget.TextInputLayout>


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

                        <Button
                            android:id="@+id/btn_submit"
                            style="@style/Widget.AppCompat.Button.Colored"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Submit"
                            android:textSize="20dp"
                            android:textStyle="bold" />

                        <ProgressBar
                            android:id="@+id/btnsubmit"
                            android:layout_width="30dp"
                            android:layout_height="30dp"
                            android:layout_centerInParent="true"
                            android:layout_gravity="center"
                            android:visibility="gone" />
                    </RelativeLayout>
                </LinearLayout>

                <!--

                                <ImageView
                                    android:layout_width="250dp"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="center_horizontal"
                                    android:layout_margin="4dp"
                                    android:adjustViewBounds="true"
                                    android:fitsSystemWindows="true"
                                    android:scaleType="fitXY"
                                    android:src="@drawable/logo" />
                -->

                <!--      <android.support.v7.widget.CardView
                          android:id="@+id/card_login"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="7dp"

                          android:layout_marginLeft="7dp"
                          android:layout_marginRight="7dp"

                          android:elevation="0dp"
                          app:cardBackgroundColor="@android:color/white"
                          app:cardElevation="4dp"
                          card_view:cardCornerRadius="2dp"
                          card_view:cardUseCompatPadding="true">-->

                <!-- </android.support.v7.widget.CardView>-->
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>


  [1]: https://i.stack.imgur.com/8tlhv.png

2 个答案:

答案 0 :(得分:0)

此后的布局设计。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/MyDarkToolbarStyle">

                // Do ur custom app bar

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimary"
                    android:gravity="end"
                    android:orientation="horizontal"
                    android:weightSum="8">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="8"
                        android:background="@color/colorPrimary"
                        android:gravity="center"
                        android:orientation="horizontal"
                        android:weightSum="8">


                        <TextView
                            android:id="@+id/txt_header"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_margin="8dp"
                            android:layout_weight="8"
                            android:gravity="left"
                            android:text="Project Edit"
                            android:textColor="@color/white"
                            android:textSize="18sp"
                            android:textStyle="bold" />


                    </LinearLayout>
                </LinearLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>

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


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

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

                       // add ur design

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

清单文件添加此主题

android:theme="@style/AppTheme.NoActionBar"

答案 1 :(得分:0)

试试这会对你有帮助。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:id="@+id/CoordinatorLayout_login"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/MyDarkToolbarStyle">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimary"
                    android:gravity="end"
                    android:orientation="horizontal"
                    android:weightSum="8">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="8"
                        android:background="@color/colorPrimary"
                        android:gravity="center"
                        android:orientation="horizontal"
                        android:weightSum="8">


                        <TextView
                            android:id="@+id/txt_header"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_margin="8dp"
                            android:layout_weight="8"
                            android:gravity="left"
                            android:text="Project Edit"
                            android:textColor="@color/white"
                            android:textSize="18sp"
                            android:textStyle="bold" />


                    </LinearLayout>
                </LinearLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarforprofile"
                android:layout_width="match_parent"
                android:layout_height="45dp"

                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                android:titleTextColor="#ffffff" />


            <LinearLayout
                android:id="@+id/profile_details"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:orientation="vertical"
                android:padding="16dp">

                <TextView
                    android:id="@+id/txtservicedetails"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"

                    android:gravity="center"
                    android:text="@string/app_name"
                    android:textColor="@color/colorAccent"
                    android:textSize="20sp"
                    android:textStyle="bold" />

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

                    <AutoCompleteTextView
                        android:id="@+id/editTextrequirement"
                        android:layout_width="match_parent"
                        android:layout_height="100dp"
                        android:hint="Your requirement?"
                        android:inputType="textMultiLine|textCapSentences"
                        android:maxLines="4"
                        android:singleLine="true"
                        android:text="" />

                </android.support.design.widget.TextInputLayout>

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

                    <AutoCompleteTextView
                        android:id="@+id/et_dateofvisit"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:focusable="false"
                        android:hint="Date Of Visit"
                        android:inputType="date"
                        android:maxLines="1"
                        android:singleLine="true"
                        android:text="" />

                </android.support.design.widget.TextInputLayout>


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

                    <AutoCompleteTextView
                        android:id="@+id/et_time"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:focusable="false"
                        android:hint="Time Of Visit"
                        android:inputType="time"
                        android:maxLines="1"
                        android:singleLine="true"
                        android:text="" />

                </android.support.design.widget.TextInputLayout>


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

                    <AutoCompleteTextView
                        android:id="@+id/et_noofperson"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:hint="Number Of Person You Need"
                        android:inputType="number"
                        android:maxLines="1"
                        android:singleLine="true"
                        android:text="" />

                </android.support.design.widget.TextInputLayout>


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

                    <AutoCompleteTextView
                        android:id="@+id/et_serviceadd"
                        android:layout_width="match_parent"
                        android:layout_height="100dp"

                        android:hint="Service Address"
                        android:inputType="textMultiLine|textCapSentences"
                        android:maxLength="2000"
                        android:maxLines="4"
                        android:singleLine="true"
                        android:text="" />

                </android.support.design.widget.TextInputLayout>


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

                    <Button
                        android:id="@+id/btn_submit"
                        style="@style/Widget.AppCompat.Button.Colored"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Submit"
                        android:textSize="20dp"
                        android:textStyle="bold" />

                    <ProgressBar
                        android:id="@+id/btnsubmit"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_centerInParent="true"
                        android:layout_gravity="center"
                        android:visibility="gone" />
                </RelativeLayout>
            </LinearLayout>

            <!--

                            <ImageView
                                android:layout_width="250dp"
                                android:layout_height="wrap_content"
                                android:layout_gravity="center_horizontal"
                                android:layout_margin="4dp"
                                android:adjustViewBounds="true"
                                android:fitsSystemWindows="true"
                                android:scaleType="fitXY"
                                android:src="@drawable/logo" />
            -->

            <!--      <android.support.v7.widget.CardView
                      android:id="@+id/card_login"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginBottom="7dp"

                      android:layout_marginLeft="7dp"
                      android:layout_marginRight="7dp"

                      android:elevation="0dp"
                      app:cardBackgroundColor="@android:color/white"
                      app:cardElevation="4dp"
                      card_view:cardCornerRadius="2dp"
                      card_view:cardUseCompatPadding="true">-->

            <!-- </android.support.v7.widget.CardView>-->
        </LinearLayout>
       </android.support.v4.widget.NestedScrollView>
        </RelativeLayout>
       </android.support.design.widget.CoordinatorLayout>