簡體   English   中英

如何設置工具欄以適應Android中的活動

[英]How to set toolbar to fit to activity In android

我正在嘗試將工具欄添加到活動中,但是如果我正在滾動,它會滾動,以下是我嘗試過的代碼,我不需要滾動到工具欄,只包含我要滾動的代碼。 我想像這樣的圖像設計如何像下面的圖像一樣設計表格 在此處輸入圖片說明

<?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

進行布局設計。

<?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"

試試這個將對您有幫助。

<?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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM