Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android选项卡式活动滚动_Java_Android_Xml_Android Activity_Scroll - Fatal编程技术网

Java Android选项卡式活动滚动

Java Android选项卡式活动滚动,java,android,xml,android-activity,scroll,Java,Android,Xml,Android Activity,Scroll,我想创建一个Android应用程序。对于我的主屏幕,我使用选项卡式活动。看起来我想要。但是当我用ScrollView环绕文本视图时,它只会滚动文本,但它应该是这样的: 所以在我滚动之前,应该先看一下: 在我滚动之后,就像这样: 以下是选项卡式活动: <?xml version="1.0" encoding="utf-8"?> 这里是文本片段: <RelativeLayout xmlns:android="http://schemas.android.com/a

我想创建一个Android应用程序。对于我的主屏幕,我使用选项卡式活动。看起来我想要。但是当我用ScrollView环绕文本视图时,它只会滚动文本,但它应该是这样的:

所以在我滚动之前,应该先看一下:

在我滚动之后,就像这样:

以下是选项卡式活动:

<?xml version="1.0" encoding="utf-8"?>


这里是文本片段:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.obware.story.Activitys.MainActivity$PlaceholderFragment">

<TextView
    android:id="@+id/section_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


有人知道我怎么做吗?

因为这是一个表格布局,我假设您使用的是片段和一个ViewPager。(即使没有viewpager,这仍然适用)

在这种情况下,您必须向活动发送一个答案,这是隐藏工具栏的基础。在基本活动中声明一个具有选项卡布局的接口

说:

现在在您的活动中实现这个接口,并超越声明的抽象方法

例如:

现在在片段中,将onScrollListener设置为ListView或RecyclerView,无论您使用什么来显示列表

现在,当列表滚动时,可以使用监听器onScrollChanged,应用逻辑调用接口方法来隐藏工具栏,如下所示:

//on some condition(say SCROLL_STATE_FLING) do the following:
((HideToolbarInterface)getActivity()).hideTheToolbar(true);

//on some other conditon(say SCROLL_STATE_IDLE unhide it:
((HideToolbarInterface)getActivity()).hideTheToolbar(false);
您可以在此处查看其他选项:


请发布一些代码?可能与
interface HideToolBarInterface{

  public void hideTheToolbar(boolean shouldbehidden);
}
public void hideTheToolbar(boolean shouldbehidden){
 if(shouldbehidden){
  getSupportActionBar().hide(); // if you have set your own toolbar, hide it similarly
 }else{
   getSupportActionBar().show(); 
 }
}
//on some condition(say SCROLL_STATE_FLING) do the following:
((HideToolbarInterface)getActivity()).hideTheToolbar(true);

//on some other conditon(say SCROLL_STATE_IDLE unhide it:
((HideToolbarInterface)getActivity()).hideTheToolbar(false);