Android-L 有哪些新的嵌套滚动 API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25136481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the new nested scrolling APIs for Android-L?
提问by nubela
I'm unable to find this info at https://developer.android.com/preview/api-overview.html
我无法在https://developer.android.com/preview/api-overview.html上找到此信息
Thanks!
谢谢!
回答by guyIntrepid
They did not draw much attention to this great new feature. I've been toying with it, and I think I've figured it out. All you have to do is is set
他们并没有引起人们对这个伟大的新功能的太多关注。我一直在玩弄它,我想我已经弄明白了。您所要做的就是设置
android:nestedScrollingEnabled="true"
android:nestedScrollingEnabled="true"
in the nested (child) scrollable view, assuming you have one somewhere inside another. This causes the child view to scroll to completion, and then allow its parent to consume the rest of the scroll. I found that I liked the opposite behavior better - parent gets scroll priority, then child follows - so I overrode the onNestedScroll
method in ScrollView as follows:
在嵌套(子)可滚动视图中,假设您在另一个内部有一个。这会导致子视图滚动到完成,然后允许其父视图消耗滚动的其余部分。我发现我更喜欢相反的行为 - 父级获得滚动优先级,然后子级跟随 - 所以我覆盖了onNestedScroll
ScrollView 中的方法,如下所示:
@Override
public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
//swap dyConsumed and dyUnconsumed
super.onNestedScroll(target, dxConsumed, dyUnconsumed, dxUnconsumed, dyConsumed);
}
You should use this new ScrollView subclass for the outer (parent) ScrollView.
您应该将这个新的 ScrollView 子类用于外部(父)ScrollView。
回答by worked
In addition to the guyIntrepid's answer, be sure to add onStartNestedScrollto your custom ScrollView or ViewPager and return true.
除了GuyIntrepid 的回答之外,请务必将onStartNestedScroll添加到您的自定义 ScrollView 或 ViewPager 并返回 true。
@Override
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes){
return true;
}
回答by juanjo
***Intento, hacer dos gridviews móviles(horizontal y verticalmente), dentro de un scrollview mas grande, pero al fijar el objetivo en los gridviews, solo me deja moverlos horizontalmente.***
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:id="@+id/scv">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical"
android:id="@+id/tt">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp"
android:gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:backgroundTint="#50000000"
android:textColor="#000000"
android:inputType="number"
android:id="@+id/NumeroPresupuesto"
android:hint="No presupuesto"
android:textColorHint="#000000"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#50000000"
android:textColor="#F6D405"
android:id="@+id/FechaPresupuesto"
android:text="FECHA"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Importe Total:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#30000000"
android:textColor="#F6D405"
android:enabled="false"
android:gravity="center"
android:layout_marginLeft="5dp"
android:id="@+id/borrar_firma"
android:text="0,00"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/ln">
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_weight="0"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="300dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<GridView
android:id="@+id/Rejilla"
android:layout_width="1000dp"
android:layout_height="match_parent"
android:background="#10000000"
android:gravity="center"
android:horizontalSpacing="0dp"
android:columnWidth="100dp"
android:numColumns="6"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp">
</GridView>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:id="@+id/ln1">
<View
android:layout_marginTop="10dp"
android:paddingTop="20dp"
android:layout_height="2dp"
android:layout_width="fill_parent"
android:background="#000000" />
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Tarifa de Colaborador"/>
<HorizontalScrollView
android:id="@+id/hsv1"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_weight="0"
android:fillViewport="true" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="300dp"
android:nestedScrollingEnabled="true">
<LinearLayout
android:id="@+id/innerLay1"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<GridView
android:id="@+id/Rejilla1"
android:layout_width="1000dp"
android:layout_height="match_parent"
android:background="#10000000"
android:gravity="center"
android:horizontalSpacing="0dp"
android:columnWidth="100dp"
android:numColumns="6"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"
</GridView>
</LinearLayout>
</ScrollView>
</HorizontalScrollView>
<View
android:layout_marginTop="10dp"
android:paddingTop="20dp"
android:layout_height="2dp"
android:layout_width="fill_parent"
android:background="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="5pt">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:gravity="center">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#50000000"
android:textColor="#FFFFFF"
android:inputType="number"
android:id="@+id/Codigo"
android:hint="Unidad"
android:textColorHint="#000000"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#50000000"
android:textColor="#FFFFFF"
android:inputType="number"
android:id="@+id/Unidad"
android:hint="Código"
android:textColorHint="#000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:gravity="center">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#50000000"
android:textColor="#FFFFFF"
android:inputType="number"
android:id="@+id/Medicion"
android:hint="Medicion"
android:textColorHint="#000000"/>
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#50000000"
android:textColor="#FFFFFF"
android:inputType="number"
android:id="@+id/PrecioPresupuestos"
android:hint="Precio"
android:textColorHint="#000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:gravity="center">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#50000000"
android:textColor="#FFFFFF"
android:inputType="number"
android:id="@+id/Importe"
android:hint="Importe"
android:textColorHint="#000000"/>
<Spinner
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/CajaIVA">
</Spinner>
</LinearLayout>
</LinearLayout>
<View
android:layout_marginTop="10dp"
android:paddingTop="20dp"
android:layout_height="2dp"
android:layout_width="fill_parent"
android:background="#000000" />
<EditText
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="5"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:gravity="top|left"
tools:textColor="#FFFFFF"
android:hint="Descripción"
android:backgroundTint="#88000000"
android:id="@+id/editText2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:gravity="center">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#000000"
android:textColor="#F6D405"
android:id="@+id/NuevoRegistro"
android:alpha="0.4"
android:text="Nuevo Registro"/>
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#000000"
android:textColor="#F6D405"
android:id="@+id/EliminarRegistro"
android:alpha="0.4"
android:text="Eliminar Registro"/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:backgroundTint="#000000"
android:textColor="#F6D405"
android:id="@+id/GrabarRegistro"
android:alpha="0.4"
android:text="Grabar Registro"/>
</LinearLayout>
</LinearLayout>
</ScrollView>