我一直在寻找这个问题的解决方案,我能找到的唯一答案似乎是" 不要将ListView放入ScrollView ".我还没有看到任何真正的解释为什么.我似乎找到的唯一原因是Google认为你不应该这样做.好吧,我做了,所以我做到了.
所以问题是,如何将ListView放入ScrollView而不将其折叠到最小高度?
我有一个android布局,其中包含scrollView许多元素.在scrollView我的底部有一个listView然后由适配器填充.
,我遇到的问题是,Android是不包括listView从scrollView作为scrollView已经具有滚动能够功能.我希望listView只要内容和主滚动视图是可滚动的.
我怎样才能实现这种行为?
这是我的主要布局:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:fillViewport="true"
android:gravity="top" >
<LinearLayout
android:id="@+id/foodItemActvity_linearLayout_fragments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
然后我以编程方式将我的组件添加到具有id:的linearlayour foodItemActvity_linearLayout_fragments.下面是加载到该线性布局中的一个视图.这是给我卷轴问题的那个.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/fragment_dds_review_textView_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reviews:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="@+id/fragment_dds_review_listView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的适配器然后填写此列表视图.
当我点击主滚动视图时,这是来自android层次结构查看器的图像:
如您所见,它排除了评论listView.
我应该能够向下滚动页面并查看8条评论,但它只向我展示了那些3,我可以滚动查看评论的小部分.我想要一个全局页面滚动
我正在尝试在相同的布局中实现包含RecyclerView和ScrollView的布局.
布局模板:
<RelativeLayout>
<ScrollView android:id="@+id/myScrollView">
<unrelated data>...</unrealated data>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_recycler_view"
/>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
问题:我可以滚动直到最后一个元素 ScrollView
我试过的事情:
ScrollView(现在ScrollView包含RecyclerView) - 可以看到卡片直到RecyclerViewviewGroup,RecyclerView而不是ScrollView其中一个视图类型是,CardView但我得到了与完全相同的结果ScrollViewandroid android-layout android-scrollview android-cardview android-recyclerview
我有一个ScrollView环绕我的整个布局,以便整个屏幕可滚动.我在这个ScrollView中的第一个元素是一个HorizontalScrollView块,它具有可以水平滚动的功能.我在horizontalscrollview中添加了一个ontouchlistener来处理触摸事件并强制视图"捕捉"到ACTION_UP事件上最近的图像.
所以我想要的效果就像股票android主屏幕,你可以从一个滚动到另一个,当你举起手指时,它会捕捉到一个屏幕.
这一切都很有效,除了一个问题:我需要从左到右几乎完全水平滑动,以便ACTION_UP进行注册.如果我至少垂直滑动(我认为许多人往往会在他们的手机上左右滑动),我会收到ACTION_CANCEL而不是ACTION_UP.我的理论是,这是因为横向视图滚动视图位于滚动视图内,并且滚动视图正在劫持垂直触摸以允许垂直滚动.
如何在水平滚动视图中禁用滚动视图的触摸事件,但仍允许在滚动视图中的其他位置正常垂直滚动?
这是我的代码示例:
public class HomeFeatureLayout extends HorizontalScrollView {
private ArrayList<ListItem> items = null;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
private static final int SWIPE_MIN_DISTANCE = 5;
private static final int SWIPE_THRESHOLD_VELOCITY = 300;
private int activeFeature = 0;
public HomeFeatureLayout(Context context, ArrayList<ListItem> items){
super(context);
setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
setFadingEdgeLength(0);
this.setHorizontalScrollBarEnabled(false);
this.setVerticalScrollBarEnabled(false);
LinearLayout internalWrapper = new LinearLayout(context);
internalWrapper.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
internalWrapper.setOrientation(LinearLayout.HORIZONTAL);
addView(internalWrapper);
this.items = items;
for(int i = 0; i< items.size();i++){
LinearLayout featureLayout = (LinearLayout) View.inflate(this.getContext(),R.layout.homefeature,null);
TextView header = (TextView) …Run Code Online (Sandbox Code Playgroud) android horizontalscrollview ontouchlistener android-scrollview
对于我的应用程序,我使用的是一个RecyclerView内部ScrollView,其RecyclerView高度基于其内容使用此库.滚动工作正在进行,但滚动时滚动不顺畅RecyclerView.当我滚动ScrollView它自己时,它滚动顺畅.
我用来定义的代码RecyclerView:
LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false);
mFriendsListView.setLayoutManager(friendsLayoutManager);
mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null));
Run Code Online (Sandbox Code Playgroud)
该RecyclerView在ScrollView:
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:id="@+id/friendsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud) android android-scrollview android-scroll android-recyclerview
有没有办法以ScrollView编程方式滚动到某个位置?
我创建了动态TableLayout,放在一个ScrollView.所以我希望在特定的操作(如点击按钮等)上,特定的行应自动滚动到顶部位置.
可能吗?
ScrollView和NestedScrollView实际有什么区别?我用过他们两个.两者都延伸了FrameLayout.我想深入了解他们两人的利弊.如果有人可以请帮助我.谢谢.
xml android android-layout android-scrollview android-nestedscrollview
我想制作一个允许我使用约束布局向下滚动的布局,但我不知道如何去做.如果scrollview是这样的constraintlayout的父级吗?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:id="@+id/Constraint"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
或者相反?也许有人可以指点我这方面的好教程或举个例子,我似乎无法找到一个.
此外,我不知道这是否是一个错误或一些配置,我不已经建立,但我看到了这样的图片 一个地方有蓝图"蓝色矩形"以外的一些成分但他们是可见的,而在我的身边,如果我将一个组件放在"白色空间"上我无法看到它或将其移动到任何地方,它出现在组件树上.
UPDATE
我找到了一种方法,可以在设计工具中滚动约束布局,使用horiontal准线向下推约束布局边框并将其扩展到设备之外,之后您可以使用引导线作为约束布局的新底部锚定组件.
android android-layout android-scrollview android-constraintlayout
所以我有一个引人入胜的问题.尽管我不是手动或以编程方式滚动我的视图,但我的WebView会在其内部数据加载后自动滚动到.
我在viewpager中有一个片段.当我第一次加载寻呼机时,它按预期工作,并显示所有内容.但是一旦我"翻页",数据就会加载,WebView会弹出到页面顶部,将视图隐藏在它上面,这是不可取的.
有谁知道如何防止这种情况发生?
我的布局看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/article_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="2dp"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/article_title"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/LL_Seperator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/text"
android:orientation="horizontal" >
</LinearLayout>
<WebView
android:id="@+id/article_content"
android:layout_width="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/article_link"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:text="View Full Article"
android:textColor="@color/article_title"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我也没注重任何事情.默认情况下,它似乎在加载后自动滚动到WebView.我该如何防止这种情况?
android android-layout android-webview android-scrollview android-viewpager