将Scroll视图仅提供给android中的edittext

时间:2017-07-22 07:39:27

标签: android xml android-layout

需要将scrollview仅提供给edittext字段而不是滚动到整个布局 在这个布局中我使用的是edittext,我只需要给予scrollview,即edittext并非所有布局 这是我的代码 See here is image

<?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"
    xmlns:card_view="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/toolbarforprofile"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:minHeight="?attr/actionBarSize"
        android:titleTextColor="#ffffff"
        app:theme="@style/ToolbarColoredBackArrow" />


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


        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:layout_marginBottom="-80dp"
            android:layout_marginTop="16dp"
            android:elevation="2dp"
            android:padding="16dp"
            android:src="@drawable/electricle" />


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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="18dp"
                android:drawableLeft="@drawable/leftarrow"

                android:textColor="@color/demo"
                android:textSize="0sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="-65.5dp"
                android:layout_marginRight="18dp"
                android:layout_marginTop="18dp">


                <LinearLayout
                    android:id="@+id/profile_details"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/demo"

                        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:layout_marginBottom="20dp"
                            android:layout_marginTop="40dp"
                            android:gravity="center"
                            android:text="@string/app_name"
                            android:textColor="#fff"
                            android:textSize="20sp"
                            android:textStyle="bold" />

                        <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="wrap_content"
                                android:layout_gravity="center"
                                android:layout_marginTop="10dp"
                                android:orientation="vertical">


                                <EditText
                                    android:id="@+id/editText_requirement"
                                    android:layout_width="match_parent"
                                    android:layout_height="70dp"
                                    android:layout_margin="3dp"
                                    android:background="#fff"
                                    android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
                                    android:gravity="top"

                                    android:hint="Your Requirement (optional)"
                                    android:inputType="textMultiLine|textCapSentences"
                                    android:padding="6dp"
                                    android:textColor="#000" />

                                <DatePicker
                                    android:id="@+id/datePicker"
                                    android:layout_width="wrap_content"
                                    android:layout_height="match_parent"
                                    android:visibility="gone" />

                                <EditText
                                    android:id="@+id/et_dateof_visit"
                                    android:layout_width="match_parent"
                                    android:layout_height="40dp"
                                    android:layout_margin="5dp"

                                    android:background="#fff"
                                    android:focusable="false"
                                    android:hint="Date Of Visit"
                                    android:inputType="date"
                                    android:maxLines="1"
                                    android:padding="5dp"
                                    android:textColor="#000" />

                                <EditText
                                    android:id="@+id/et_time"
                                    android:layout_width="match_parent"
                                    android:layout_height="40dp"
                                    android:layout_margin="5dp"
                                    android:background="#fff"
                                    android:focusable="false"
                                    android:hint="Time Of Visit"
                                    android:inputType="time"
                                    android:maxLines="1"
                                    android:padding="5dp"
                                    android:textColor="#000" />

                                <EditText

                                    android:id="@+id/et_noofperson"
                                    android:layout_width="match_parent"
                                    android:layout_height="40dp"
                                    android:layout_margin="5dp"
                                    android:background="#fff"
                                    android:focusable="true"
                                    android:hint="No Of Person You Need"
                                    android:inputType="number"
                                    android:maxLength="2"
                                    android:maxLines="1"
                                    android:padding="5dp"
                                    android:singleLine="true"
                                    android:text="" />

                                <EditText

                                    android:id="@+id/et_serviceaddress"
                                    android:layout_width="match_parent"
                                    android:layout_height="70dp"
                                    android:layout_margin="5dp"
                                    android:background="#fff"
                                    android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/-,: "
                                    android:focusable="true"
                                    android:gravity="top"
                                    android:hint="Service Address"
                                    android:inputType="textMultiLine|textCapSentences"
                                    android:maxLines="4"
                                    android:padding="10dp"
                                    android:singleLine="true"
                                    android:text="" />


                            </LinearLayout>
                        </android.support.v4.widget.NestedScrollView>


                    </LinearLayout>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginBottom="20dp"
                        android:layout_marginTop="-20dp"
                        android:gravity="center">

                        <Button
                            android:id="@+id/btn_submit"
                            style="@style/Widget.AppCompat.Button.Colored"
                            android:layout_width="wrap_content"
                            android:layout_height="45dp"
                            android:layout_gravity="center"
                            android:layout_marginTop="20dp"
                            android:background="@drawable/rounded_green"
                            android:ems="10"
                            android:gravity="center"
                            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>


            </LinearLayout>

        </LinearLayout>


    </LinearLayout>

</LinearLayout>

3 个答案:

答案 0 :(得分:0)

尝试以下内容,

 View.OnTouchListener touchListener = new View.OnTouchListener() 
{
        public boolean onTouch(final View v, final MotionEvent motionEvent) 
{
            v.getParent().requestDisallowInterceptTouchEvent(true);
            switch (motionEvent.getAction() & MotionEvent.ACTION_MASK)
 {
                case MotionEvent.ACTION_UP:
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
            }
            return false;
        }
    };

我希望这可以帮到你,一切顺利。

答案 1 :(得分:0)

我仍然不确定我是否理解你的问题。我假设您要进行EditText(s)滚动,同时将顶部TextView和底部Button固定到位。

试试这个。我首先将LinearLayout作为主要容器,然后将TextViewScrollViewButton添加为子布局。

然后,所有需要滚动的EditText(s)都可以添加到LinearLayout作为孩子添加到ScrollView

查看此代码

<LinearLayout 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: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="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:minHeight="?attr/actionBarSize"
        android:titleTextColor="#ffffff"/>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:text="@string/app_name"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

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

            <!--Put all your scrollable content in here-->

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </ScrollView>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_gravity="center"/>

</LinearLayout>

我已将layout_weight属性提供给ScrollView,以确保Button始终位于底部。

PS:如果这不是您需要的解决方案,请发表评论。

答案 2 :(得分:0)

机器人:scrollHorizo​​ntally =&#34;真&#34;使用这个

相关问题