我在屏幕上创建了视差效果,创建了三个选项卡,每个选项卡中都有多个编辑文本。所以当我在编辑文本之外滚动时,它滚动没有问题,但当我在编辑文本上滚动时,屏幕不滚动。mainactivity.xml
<android.support.design.widget.CoordinatorLayout 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:id="@+id/layout_group_details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout_Myprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_my_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:minHeight="?attr/actionBarSize"
app:contentScrim="@android:color/transparent"
app:expandedTitleMarginStart="5dp"
app:expandedTitleTextAppearance="@style/TransparentText"
app:statusBarScrim="@android:color/white">
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/relativelayout_profilepic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
tools:context=".MainActivity"
android:layout_marginTop="?attr/actionBarSize">
<com.oi.managemygroup.util.SelectableRoundedImageView
android:id="@+id/imageView_of_my_profile_ampl"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_avtar_new"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
app:sriv_border_color="@color/bluecolor"
app:sriv_border_width="2dp"
android:layout_marginLeft="10dp"
android:contentDescription="@string/app_name"
app:sriv_left_bottom_corner_radius="@dimen/corner_radius_for_mmg_images"
app:sriv_left_top_corner_radius="@dimen/corner_radius_for_mmg_images"
app:sriv_right_bottom_corner_radius="@dimen/corner_radius_for_mmg_images"
app:sriv_right_top_corner_radius="@dimen/corner_radius_for_mmg_images" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview_userName_amps"
android:text="User Name"
android:textSize="16dp"
android:layout_marginLeft="10dp"
android:textColor="@color/blackcolor"
android:layout_below="@+id/imageView_of_my_profile_ampl"
android:layout_marginTop="5dp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imageView_of_my_profile_ampl"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/view_Vertical_Line">
<TextView
android:id="@+id/textView_forum_created_count_Text_ampl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forumsncreated"
android:gravity="center"
android:textColor="#B3B3B3"
android:textSize="15sp" />
<TextView
android:id="@+id/textView_forum_created_count_ampl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:layout_marginTop="5dp"
android:text="0"
android:textColor="#0c83bd"
android:textSize="16sp"
android:layout_toLeftOf="@+id/view_Vertical_Line" />
</LinearLayout>
<View
android:id="@+id/view_Vertical_Line"
android:layout_width="0.5dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:background="#E5E5E5"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/view_Vertical_Line">
<TextView
android:id="@+id/textView_forum_participated_count_Text_ampl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Forums n participate"
android:textColor="#B3B3B3"
android:textSize="15sp" />
<TextView
android:id="@+id/textView_forum_participated_count_ampl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="0"
android:layout_marginTop="5dp"
android:textColor="#0c83bd"
android:textSize="16sp"
android:layout_below="@+id/textView_forum_participated_count_Text_ampl"
android:layout_toRightOf="@+id/view_Vertical_Line" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<include
android:id="@+id/toolbar_my_profile"
layout="@layout/toolbar_my_profile_screenr" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tablinear_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_of_profile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="6dp"
android:layout_marginTop="5dp"
android:minHeight="?attr/actionBarSize" />
<View
android:id="@+id/view_Horizontal_Line"
android:layout_width="fill_parent"
android:layout_height=".5dp"
android:layout_below="@+id/tab_layout_of_profile"
android:background="#E5E5E5"
android:orientation="horizontal" />
<android.support.v4.view.ViewPager
android:id="@+id/pagerofprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/view_Horizontal_Line"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<TextView
android:id="@+id/textview_layout_footer"
android:layout_width="fill_parent"
android:layout_marginTop="7dp"
android:layout_height="7dp"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:background="@color/bluecolor" />
</RelativeLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
and tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible"
android:id="@+id/LinearLayout_Address_details"
android:paddingBottom="5dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="5dp"
android:weightSum="7">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_address1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/address1"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_address1_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="textPostalAddress|textMultiLine"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollbars="horizontal|vertical"
android:textColor="#B3B3B3"
android:textSize="16sp"
android:maxLines="2"
android:maxLength="25"
android:lines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_address2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/address2"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_address2_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="textPostalAddress|textMultiLine"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollbars="horizontal|vertical"
android:textColor="#B3B3B3"
android:textSize="16sp"
android:maxLines="2"
android:maxLength="25"
android:lines="1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_address3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/address3"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_address3_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="textPostalAddress|textMultiLine"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollbars="horizontal|vertical"
android:textColor="#B3B3B3"
android:textSize="16sp"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_city"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/city"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_city_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="textCapSentences"
android:maxLength="20"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollHorizontally="true"
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:singleLine="true"
android:textColor="#B3B3B3"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_state"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/state"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_state_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="textCapSentences"
android:maxLength="20"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollHorizontally="true"
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:singleLine="true"
android:textColor="#B3B3B3"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_country"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/country"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_country_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="text"
android:maxLength="20"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollHorizontally="true"
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:singleLine="true"
android:textColor="#B3B3B3"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView_pin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:text="@string/pin"
android:textColor="#B3B3B3"
android:textSize="16sp" />
<EditText
android:id="@+id/editText_pin_ampl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:ems="10"
android:inputType="number"
android:maxLength="8"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#B3B3B3"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
参考链接
EditText EtOne = (EditText) findViewById(R.id.EditText01);
EtOne.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.comment1) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
这是因为您的EditText正在捕获您的滚动(因为EditText也可以水平滚动)。
要解决你的问题,你必须打电话;
editText.setFocusable(false);
editText.setFocusableInTouchMode(false);
所以它不能窃取焦点。您还必须在EditText
上附加一个点击侦听器,然后将焦点重新打开并对其进行聚焦。
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setFocused(true)
}
});
您可能还必须为焦点更改设置侦听器,并在焦点丢失时再次关闭焦点!基本上,您必须手动完成所有操作。在Android指南中,建议不要将EditText
放在ScrollView
中,所以要做到这一点,你必须非常"黑客",你可能最好只是改变你的应用程序的流程。