标签: android-scrollview

Scrollview超越了屏幕底部

我突然遇到Scrollview超出屏幕底部的问题,这样即使你一直向下滚动它也不会显示它的所有内容.XML是:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFFFF">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:background="#FFBBBBBB"
        android:orientation="vertical" >
        <View
            android:layout_width="100dp"
            android:layout_height="300dp"
            android:layout_margin="15dp"
            android:layout_gravity="center_horizontal"
            android:background="#FFDDDDFF"/>
        <View
            android:layout_width="100dp"
            android:layout_height="300dp"
            android:layout_margin="15dp"
            android:layout_gravity="center_horizontal"
            android:background="#FFDDDDFF"/>
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

它没有比这更简单.一旦你完全向下滚动(如滚动条的形状所示),你应该看到底部的白色边缘,但这就是它的样子:

滚动视图的底部

与顶部比较:

滚动视图的顶部

底部应该看起来像顶部,只能颠倒.这种情况发生在模拟器,真实设备和我尝试过的几乎所有Android版本中.我不知道我做错了什么(如果有的话......).

请不要猜测,也不要从臀部射击!只测试过答案.我已经浪费了足够的时间在这上面了.谢谢.

android android-scrollview

9
推荐指数
2
解决办法
3914
查看次数

在android中的Scrollview中设置Viewpager高度

我必须在scrollview中显示一个viewpager(在pager行中的图像下方的图像和文本).我正在从网上下载图像,文本并在寻呼机行中显示.我在srollview中包含了viewpager以支持横向模式.

 <com.xxx.myapp.android.ui.CustomScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:fadingEdge="none"
    android:fillViewport="true"
    android:gravity="center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="blocksDescendants"
        android:orientation="vertical" >

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="800dp"
            android:layout_gravity="top"
            android:layout_marginTop="10dp" />  
    </LinearLayout>
</com.xxx.myapp.android.ui.CustomScrollView> 
Run Code Online (Sandbox Code Playgroud)

这是CustomScrollView.问题是如何根据子高度设置视图寻呼机高度,以便我可以滚动屏幕直到视图寻呼机项目结束.如果我将view pager height设置为wrapcontent,则viewpager中不会显示任何内容.如果我设置了800dp,那么我可以看到寻呼机项目,但屏幕上有不必要的滚动.我不希望我的滚动视图滚动超出寻呼机儿童的高度.请帮我.

android android-scrollview android-viewpager

9
推荐指数
4
解决办法
1万
查看次数

Android ScrollView在底部被切断

我正在尝试以编程方式将从HTML文件中选取的表单字段添加到LinearLayout.我在底部有一个下一个按钮,但它在显示屏上不断切断.我在平板电脑上尝试过,它仍然没有显示出来.

这是应用程序的屏幕截图: 截图

正如您所看到的,元素正在渲染,但最后一个元素由于某种原因而在屏幕上运行.

片段的XML:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".dataInput.PropertyInfoFragment"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:paddingLeft="20dp"
    android:paddingRight="20dp">

    <ScrollView
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/linear_layout_property_info"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            </LinearLayout>
            <Button
                android:id="@+id/nextButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/next"
                android:background="@color/colorPrimary"
                android:textColor="@android:color/white"/>
        </LinearLayout>

    </ScrollView>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

调用Activity的XML:

<?xml version="1.0" encoding="utf-8"?>
<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/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".dataInput.DataInputActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin" …
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout android-fragments android-scrollview

9
推荐指数
4
解决办法
7755
查看次数

Firebase在滚动时动态加载数据

我需要知道如何在使用Firebase滚动时动态加载数据.如果我使用Firebase查询数据,则必须一次性加载所有数据或始终更改数据.我希望每个限制使用Firebase加载数据,并且在达到此限制后,加载更多数据并且越来越多.

它基本上就像Facebook的时间线 - 作为一个社交网络.

例如:我想从Firebase获得最低限度50的最新记录.达到此限制后,我将下载下50个数据.我想用RecyclerView而不是FirebaseRecycler上课.

FirebaseRecyclerAdapter无法解决我的问题.感谢帮助.我需要点视图布局的facebook时间线等loadind数据,以及点视图数据库的加载数据Firebase(50到50个.下载50个数据,达到限制,加载底部布局的更多数据到50).

你可以帮帮我吗?

android android-scrollview firebase android-recyclerview firebase-realtime-database

9
推荐指数
1
解决办法
4963
查看次数

如何在android中的gridview中添加可滚动的标题?

我试图在android中的gridview布局中添加一个可滚动的标题,我尝试过我可以在网上找到的所有东西,但我不能让它工作,这种类型的布局出现在一些流行的应用程序,如Facebook和Instagram但我无法找到任何可以让我了解如何实际操作的示例代码,任何人都知道如何实现这一目标?将gridview添加到scrollview也不起作用,下面是一些照片,说明了我想要实现的目标.

这是在卷轴之前:

在滚动之前

这是在滚动之后: 滚动后

android android-layout android-gridview android-scrollview

8
推荐指数
1
解决办法
5349
查看次数

了解如何使用OverScroller类

我正在考虑在我的项目中添加过度滚动(而不是颜色变化),但即使在阅读了API文档和这里的几个问题后,我仍然不明白我需要做些什么才能使它工作.

根据OverScroller的API文档:" 这个类封装了滚动,能够超越滚动操作的范围.在大多数情况下,这个类是Scroller的直接替代品. "

我之前在父类中有一个Scroller对象:

public boolean onTouchEvent(MotionEvent ev) {   
    ....// code to calculate deltas
     if (deltaY != 0 || deltaX != 0)
            scrollBy(deltaX, deltaY);
}
Run Code Online (Sandbox Code Playgroud)

然后我去改变它:

if (deltaY != 0 || deltaX != 0)
            overScrollBy(deltaX, deltaY, getScrollX(), getScrollY(),
                child.getRight() - getWidth(), child.getBottom() - getHeight(), 
                    OVERSCROLL_DISTANCE, OVERSCROLL_DISTANCE, false);
Run Code Online (Sandbox Code Playgroud)

现在滚动根本不起作用!fling()作为一个替代滴,但不滚动....

总之,我有两个问题:

  1. 为什么滚动不起作用overScrollBy?我是否必须添加其他代码才能使其正常工作?
  2. 我为什么要打电话mScroller.fling(),只overScrollBy()?为什么不mScroller.overScrollBy()呢?它是否以某种方式构建在View课堂上?

这可能是非常明显的,但我在这里挣扎.任何帮助将非常感谢,谢谢!

android android-scrollview android-overscoll android-scroll

8
推荐指数
1
解决办法
1824
查看次数

当listitem在recyclerview中可见时播放/暂停视频

我已经实现了一个recyclerview,我在其中添加纹理视图作为列表项来播放来自url的视频.现在像藤蔓和Instagram应用程序我想播放视频,当它在recyclerview中可见,并在listitem离开屏幕时停止/暂停视频.以下是我的代码:

VideosAdapter类:

public class VideosAdapter extends RecyclerView.Adapter<VideosAdapter.ViewHolder> {

private static String TAG = "VideosAdapter";

Context context;
private ArrayList<String> urls;
RecyclerView recyclerView;

public static class ViewHolder extends RecyclerView.ViewHolder {

    public TextureView textureView;
    public TextView textView;

    public ViewHolder(View v) {
        super(v);
        textureView = (TextureView) v.findViewById(R.id.textureView);
        textView = (TextView) v.findViewById(R.id.textView);

    }
}

public VideosAdapter(Context context, RecyclerView recyclerView, final ArrayList<String> urls) {

    this.context = context;
    this.recyclerView = recyclerView;
    this.urls = urls;

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) { …
Run Code Online (Sandbox Code Playgroud)

android-scrollview android-textureview android-recyclerview onscrollchanged

8
推荐指数
1
解决办法
1628
查看次数

iOS喜欢Android上的滚动效果

我想在我的应用程序中实现类似iOS的反弹过度滚动效果.

我遇到了这个链接,建议创建一个自定义ScrollView.但问题是,当我快速上下滚动它工作正常但是一旦我拉动屏幕的底部或顶部它就会卡住而且效果不再起作用.

作为我想要实现的那种动画的一个例子,你可以看看这个:

这是我目前的代码:

public class ObservableScrollView extends ScrollView
{
    private static final int MAX_Y_OVERSCROLL_DISTANCE = 150;

    private Context mContext;
    private int mMaxYOverscrollDistance;

    public ObservableScrollView(Context context)
    {
        super(context);
        mContext = context;
        initBounceScrollView();
    }

    public ObservableScrollView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        mContext = context;
        initBounceScrollView();
    }

    public ObservableScrollView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        mContext = context;
        initBounceScrollView();
    }

    private void initBounceScrollView()
    {
        //get the density of the screen and do some maths …
Run Code Online (Sandbox Code Playgroud)

java animation android android-animation android-scrollview

8
推荐指数
2
解决办法
9682
查看次数

onScrollChanged在scrollView中多次触发滚动结束

我已经实现了一个侦听器类来检测滚动视图的结尾,参考链接https://gist.github.com/marteinn/9427072

public class ResponsiveScrollView extends ScrollView {

private OnBottomReachedListener listener;

public ResponsiveScrollView(Context context) {
    super(context);
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    View view = getChildAt(getChildCount()-1);
    int diff = view.getBottom()-(getHeight()+getScrollY());
    if (diff == 0 && listener!= null) {
        listener.onBottomReached(this);
    }
    super.onScrollChanged(l, t, oldl, oldt);
}

public OnBottomReachedListener getBottomChangedListener() {
        return listener;
}

public void setBottomReachesListener(OnBottomReachedListener onBottomReachedListener) {
    this.listener = onBottomReachedListener;
}

public interface OnBottomReachedListener {
    public void onBottomReached(View view);
   }
}
Run Code Online (Sandbox Code Playgroud)

监听器设置为scrollView:

scrollView.setBottomReachesListener(new …
Run Code Online (Sandbox Code Playgroud)

android scrollview android-scrollview onscrolllistener onscrollchanged

8
推荐指数
2
解决办法
1122
查看次数

切换片段时跳跃滚动

在 ScrollView 中,我在两个不同高度的片段之间动态切换。不幸的是,这会导致跳跃。人们可以在以下动画中看到它:

  1. 我正在向下滚动,直到到达“显示黄色”按钮。
  2. 按“显示黄色”会用一个微小的黄色片段替换一个巨大的蓝色片段。发生这种情况时,两个按钮都会跳到屏幕的末尾。

当切换到黄色片段时,我希望两个按钮都保持在相同的位置。那怎么办呢?

卷

源代码分别位于https://github.com/wondering639/stack-dynamiccontent https://github.com/wondering639/stack-dynamiccontent.git

相关代码片段:

活动_main.xml

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

<androidx.core.widget.NestedScrollView 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/myScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="800dp"
        android:background="@color/colorAccent"
        android:text="@string/long_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button_fragment1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:text="show blue"
        app:layout_constraintEnd_toStartOf="@+id/button_fragment2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <Button
        android:id="@+id/button_fragment2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:text="show yellow"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/button_fragment1"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/button_fragment2">

    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

主活动.kt

package com.example.dynamiccontent

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class MainActivity : …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments android-scrollview fragmentmanager

8
推荐指数
1
解决办法
1950
查看次数