Java 菜单选项卡不';不回答
目前我正在为我的应用程序制作UI。我使用了一些新的功能。两者都很好。我甚至在一个项目中实现了它们,但这就是问题所在——当我触摸主页和事件选项卡时,它们没有响应(应该打开它所代表的页面),但当我在选项卡之间滑动时,它们会发生变化 这是我的布局代码。这就是问题所在。我敢肯定Java 菜单选项卡不';不回答,java,android,android-layout,android-viewpager,android-tabs,Java,Android,Android Layout,Android Viewpager,Android Tabs,目前我正在为我的应用程序制作UI。我使用了一些新的功能。两者都很好。我甚至在一个项目中实现了它们,但这就是问题所在——当我触摸主页和事件选项卡时,它们没有响应(应该打开它所代表的页面),但当我在选项卡之间滑动时,它们会发生变化 这是我的布局代码。这就是问题所在。我敢肯定 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.c
<LinearLayout 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">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParalaxOffset="100dp"
sothree:umanoDragView="@+id/dragView">
<!-- MAIN CONTENT -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff0000">
<com.ui.test.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<!-- SLIDING LAYOUT -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55eeeeee"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="14sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>
<Button
android:id="@+id/follow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="14sp"
android:gravity="center_vertical|right"
android:paddingRight="10dp"
android:paddingLeft="10dp"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitStart"
android:src="@drawable/daimage" >
</ImageView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
从文件中: 默认情况下,整个面板将充当拖动区域,并将拦截单击和拖动事件。可以使用
setDragView
方法或umanoDragView
属性将拖动区域限制为特定视图
因此,我假设,向上滑动面板会消耗您在选项卡上的单击—只需按照文档建议设置属性即可 根据Amy的回答,假设SlideingAppAnel正在阻止选项卡按钮的onTouch,那么您可以使用onTouch eventlistener来禁止父布局拦截任何类似的触摸事件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Creating The Toolbar and setting it as the Toolbar for the activity
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);
// THIS PART, ADD CODE HERE !
tabs.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
}
编辑1:
“向上滑动”面板类似于其子面板顶部的覆盖,因此,如果将选项卡布局保留在子面板中,则“向上滑动”面板的条形图将位于选项卡条的正上方,并且此“向上滑动”面板的条形图将阻止选项卡条接收任何单击或触摸事件,因此
当您实际尝试触摸或单击选项卡时,您实际上并没有触摸/单击选项卡,因为向上滑动面板位于其顶部。您需要做的是将SlidingTableOut置于SlidingPanel布局之外
<LinearLayout 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">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!--this is outside sliding up panel layout-->
<com.example.www.slidinguppanelapp.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f0f0"/>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/sliding_layout"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoDragView="@+id/dragView"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp">
<!-- MAIN CONTENT -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<!-- SLIDING LAYOUT -->
<LinearLayout
android:id="@+id/dragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55eeeeee"
android:clickable="true"
android:focusable="false"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="14sp"/>
<Button
android:id="@+id/follow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="14sp"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitStart"
android:src="@drawable/blur_bg">
</ImageView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>
把它放在你的onCreate()中将
umanoDragView
添加到com.ui.test中。滑动布局不会改变任何东西。将它添加到你的viewpagermovedsothree:umanoDragView=“@+id/dragView=”
到ViewPager
-没有任何变化,ViewPager是错误的。您必须将umanoDragView添加到视图中,您希望在其中启用拖动-因为您希望拥有viewpager,我建议在第一个相对布局的底部添加一个简单的元素,并确保那里没有可单击的内容。我不知道它是否有效,但您可以尝试将属性添加到第二个子项(LinearLayout),因此只能从那里拖动?嗨,Oleksandr,尝试从设计支持库切换到?。。可能响应更快。显示java代码。我所能说的是,它已经超越了它,你的图书馆里有没有选出来的或类似的东西?我在问题中添加了MainActivity.java
,这是一个可以解决这个问题的方法。其余的和我提供的链接是一样的。我已经花了150次的时间来回答这个问题。如果仍然没有得到答复,那将是一件遗憾的事。不要担心,你有2天的时间,我在这里,会在24小时内给你一个解决方案。我试着快速重新创建场景。谢谢你的回答。我已经将其添加到MainActivity.java中,但在第一行出现了以下错误:这一行有多个标记-标记“setOnTouchListener”上的语法错误,无效的AnnotationName-语法错误,插入“}”以完成块-标记上的语法错误,错误放置的构造
以及标记上的这一语法错误“}”,最后一个构造函数的构造函数headerName
无效。我该怎么办?那我该怎么解决呢?这些看起来像语法错误。你能发布整个类代码吗?我必须查看完整的类代码才能看到花括号结构。我在问题中提供了花括号结构。不,把代码放在你实际有权访问tabs变量的地方,将代码放在OnCreate的末尾有很多错误。检查更新问题的代码和屏幕截图
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Creating The Toolbar and setting it as the Toolbar for the activity
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
adapter = new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);
// THIS PART, ADD CODE HERE !
tabs.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
}
<LinearLayout 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">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!--this is outside sliding up panel layout-->
<com.example.www.slidinguppanelapp.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f0f0"/>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/sliding_layout"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoDragView="@+id/dragView"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp">
<!-- MAIN CONTENT -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<!-- SLIDING LAYOUT -->
<LinearLayout
android:id="@+id/dragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55eeeeee"
android:clickable="true"
android:focusable="false"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="14sp"/>
<Button
android:id="@+id/follow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="14sp"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="fitStart"
android:src="@drawable/blur_bg">
</ImageView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</LinearLayout>
tabs.setOnTouchListener(new View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});