标签: android-scrollview

ViewPager内的ScrollView会自动滚动到中间

我有一个ViewPager包含同一个片段的几个实例,这个片段包含一篇文章.文章视图层次结构非常简单,标题,横幅图像,副标题和正文; 除标题之外的所有内容都包含在scrollview中.

问题是,当您滑动到新页面时,片段会在顶部显示视图,然后立即滚动到容器的中间.(事实上​​,它滚动到TextView的开头,ID为:article_content)

我已在问题的底部发布了布局.

现在,ViewPager设置了一个简单的a实现FragmentStatePagerAdapter,这里是代码:

class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

    Bundle args;
    int count;

    public ScreenSlidePagerAdapter(FragmentManager fm) {
        super(fm);
        this.count = 8;
    }

    @Override
    public Fragment getItem(int position) {
        ArticleFragment mPrimaryFragment = new ArticleFragment();
        args = new Bundle();
        args.putString(ArticleFragment.KEY_ARTICLE_URL, mCurArticleLink);
        mPrimaryFragment.setArguments(args);
        return mPrimaryFragment;            
    }

    @Override
    public int getCount() {
        return count;
    }   
}
Run Code Online (Sandbox Code Playgroud)

Fragment本身也很简单.首先,我检查期间onCreate是否有缓存的文章,我打电话给onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.apk_article_view, null);

    mTitle = (TextView) …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-viewpager

22
推荐指数
2
解决办法
2万
查看次数

ScrollView禁用焦点移动

我有一个简单的输入表格; 它是ScrollView中带有EditTexts的垂直LinearLayout.

<ScrollView android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">
            <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:padding="10dip"
                  android:gravity="center_vertical"
                  android:orientation="horizontal">
                  <TextView style="@style/Text"
                         android:text="Name"/>
                  <EditText style="@style/EditBox"/>
            </LinearLayout>
            <View style="@style/Divider"/>
            <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:padding="10dip"
                  android:gravity="center_vertical"
                  android:orientation="horizontal">
                  <TextView style="@style/Text"
                         android:text="Password"/>
                  <EditText style="@style/EditBox"/>
            </LinearLayout>               
            ... 
     </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

当用户滚动表单时,它会自动将其焦点移动到可见的EditText.可以禁用此类行为并始终将焦点放在当前通过触摸选择的EditText上吗?

我知道这可能是一个功能,但我需要禁用它.

谢谢!

android focus android-scrollview

21
推荐指数
4
解决办法
3万
查看次数

ConstraintLayout中的android RecylerView不会滚动

我在约束布局中有一个recyclerView,我无法使其滚动,列表只是在屏幕下方继续,没有滚动可能性.如果我将布局转换为相对布局,滚动工作正常.

怎么才能让它滚动?

以下XML显示了我的布局,Recycler视图位于底部.布局在屏幕顶部有一个图像和描述.此屏幕设置占用屏幕的30%.然后是一个分隔符和一个应该占据屏幕其余部分并且无法滚动的回收器视图

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gradient_top">

   <android.support.v7.widget.AppCompatImageView
        android:id="@+id/imageViewLock"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="16dp"
        app:layout_constraintBottom_toTopOf="@+id/textViewPermissionsTitle"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_phone_lock"/>

    <TextView
        android:id="@+id/textViewPermissionsTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:gravity="center"
        android:paddingLeft="24dp"
        android:paddingRight="24dp"
        android:text="@string/allow_permissions"
        android:textColor="@color/white"
        android:textSize="@dimen/description_text_size"
        app:layout_constraintBottom_toTopOf="@+id/guideline1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.3"/>


    <View
        android:id="@+id/viewSeparator"
        android:layout_width="match_parent"
        android:layout_height="0.7dp"
        android:layout_marginTop="10dp"
        android:background="@color/bright_blue"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline1"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerViewPermissions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="1dp"
        android:scrollbarThumbVertical="@color/white"
        android:scrollbars="vertical"
        app:layout_constraintTop_toBottomOf="@+id/viewSeparator" />


</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-recyclerview android-constraintlayout

19
推荐指数
2
解决办法
9735
查看次数

我可以在回到像ListView这样的片段之后保持ScrollView的位置吗?

我试过使用ScrollView和ListView.

我想出如果我使用ListView并单击其中一个项目,则将当前片段替换为下一个片段,然后按回按钮以显示片段.ListView的滚动位置将保持在相同的位置.但是如果我使用ScrollView,它就不会.

我不明白为什么他们不一样?如何在按下按钮后让ScrollView保持其位置?

实际上,我在StackOverflow上搜索了一些答案.但我想知道原因,并找到一种更简单的方法使ScrollView和ListView具有相同的行为.

请帮我!谢谢!

android android-listview android-fragments android-scrollview

18
推荐指数
1
解决办法
3703
查看次数

在ScrollView中使用RecyclerView,灵活的Recycler项目高度

我想知道有没有可能的方法来使用RecyclerView

在此之前,我在ScrollView中使用具有修复高度的 RecyclerView,但这次我不知道项目的高度.

提示:我在4天前提出这个问题之前,先阅读了堆栈问题的所有问题和解决方案.

更新: 一些解决方案学习如何自己滚动RecyclerView但我想展示这个扩展.

android scrollable android-scrollview android-recyclerview

18
推荐指数
5
解决办法
3万
查看次数

使中间元素卡在标题中(ScrollView/ListView)

我想制作一个在第一个ScrollView(或ListView)中间显示的元素,然后在滚动时卡在屏幕的标题中.

它是CSS + JS中的原型实现:http://jsfiddle.net/minhee/aPcv4/embedded/result/.

乍一看我会ScrollView考虑包括ListView,但官方文档说:

您永远不应该使用带有ListView的ScrollView,因为ListView负责自己的垂直滚动.最重要的是,这样做会使ListView中的所有重要优化都无法处理大型列表,因为它有效地强制ListView显示其整个项目列表以填充ScrollView提供的无限容器.

那么,我可以尝试用什么方法来实现这个UI?

更新:我尝试过StickyListHeaders,但是:"它目前不可能在标题中有交互元素,按钮,开关等只有在标题没有卡住时才会起作用."另外,我发现它不适合这种情况.我不需要多个标题,但只需要一个中间元素卡在标题中.

android android-listview android-scrollview

17
推荐指数
1
解决办法
4648
查看次数

如何在Webview中向下滚动时隐藏ActionBar /工具栏

在Google Chrome和Play商店中.应用程序可以在滚动时隐藏操作栏,并允许用户方便地浏览.请帮我这样做.

我使用onTouchListener进行webview它不起作用.

mWebView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        getSupportActionBar().show();
                            break;
                    case MotionEvent.ACTION_UP:
                        getSupportActionBar().hide();
                            break;
                    default: break;
                }
                return false;
            }
        });
Run Code Online (Sandbox Code Playgroud)

提前致谢

android android-webview android-scrollview android-scroll

17
推荐指数
2
解决办法
2万
查看次数

如何制作zoomable scrollview?

在我的Android应用程序中,我需要创建可缩放的活动.我在这里找到了用于缩放线性布局的有用代码.但在我的应用程序中,几个活动以scrollview开头,此代码无法识别scrollview.如何为可滚动活动进行捏缩放?这是我的布局之一.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollViewZoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >

<LinearLayout
    android:id="@+id/wd_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

    <!-- Start Circle -->

    <TableRow
        android:id="@+id/row_circl1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:background="@color/purple_color" >

        <RelativeLayout
            android:id="@+id/circle_layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white_color" >

            <ImageView
                android:id="@+id/img_engin_circle1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:background="@drawable/circle_engin_bg"
                android:contentDescription="TODO" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/circle_layout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white_color" >

            <ImageView
                android:id="@+id/img_engin_circle2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:background="@drawable/circle_engin_bg"
                android:contentDescription="TODO" />
        </RelativeLayout>
    </TableRow>

    <TableRow
        android:id="@+id/row_name_circle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginTop="30dp" >

        <RelativeLayout
            android:id="@+id/circle_name_layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="-15dp"
            android:background="@color/white_color" >

            <ImageView
                android:id="@+id/img_name_circle1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout android-scrollview android-activity

16
推荐指数
2
解决办法
2万
查看次数

ScrollView中的PercentRelativeLayout

我创建了一个使用ScrollViewa PercentRelativeLayout作为其子项的布局.它不适用于Lollipop和旧设备,但在Marshmallow设备上工作正常.请检查以下代码:

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <android.support.percent.PercentRelativeLayout
        android:id="@+id/scrollContent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_heightPercent="100%"
        app:layout_widthPercent="50%">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_red_dark"
            android:text="kkjknadko"
            android:textColor="@android:color/black"
            app:layout_heightPercent="10%"
            app:layout_widthPercent="50%"/>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView1"
            android:text="Abcaad"
            android:textColor="@android:color/black"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="10%"
            app:layout_widthPercent="50%"/>

        <TextView
            android:id="@+id/textview3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textview2"
            android:background="@android:color/holo_red_dark"
            android:text="Abcd"
            android:textColor="@android:color/black"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="10%"
            app:layout_widthPercent="50%"/>

        <TextView
            android:id="@+id/textview4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textview3"
            android:text="Abcd"
            android:textColor="@android:color/black"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="10%"
            app:layout_widthPercent="50%"/>

        <TextView
            android:id="@+id/textview5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textview4"
            android:background="@android:color/holo_red_dark"
            android:text="Abcd"
            android:textColor="@android:color/black"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="10%"
            app:layout_widthPercent="50%"/>

        <TextView
            android:id="@+id/textview6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textview5"
            android:text="Abcd"
            android:textColor="@android:color/black"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="10%"
            app:layout_widthPercent="50%"/>

        <TextView
            android:id="@+id/textview7"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-5.0-lollipop android-6.0-marshmallow android-percentrelativelayout

16
推荐指数
2
解决办法
1810
查看次数

ScrollView内部的RecyclerView,某些项目未显示

我在ScrollView中有一个RecyclerView,如下所示:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--other stuff-->

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

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"/>

    </LinearLayout>

    <!--other stuff-->

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

这个RecyclerView项目是一个RelativeLayout,其中有一个EditText和其他的观点.在layout_heightRelativeLayoutEditText既是wrap_content.用户可以在EditText没有任何长度/线条限制的情况下输入,以便每个项目的高度不同.

然后我发现getItemCount()Adapter返回true值但onBindViewHolder()被调用错误的时间(少于它应该),因此不足以显示所有项目.

我发现这只会在我写的时候发生recyclerView.setNestedScrollingEnabled(false).但我不能删除这一行.因为如果我这样做了,RecyclerView它就不会顺畅地滚动,并且与其他内部ScrollViewScrollView自身的观点不一致.

这发生在6.0但不是4.1.

我在此页面与Google进行了沟通:https://code.google.com/p/android/issues/detail?id = 213914他告诉我这是一个错误修复程序RecyclerView.您可以访问该页面,以便更好地理解问题和我的目标(有一个小样本项目可以显示问题).即使是现在我也不同意他,我想解决这个问题.请帮忙,提前谢谢.

android android-scrollview android-support-library android-recyclerview android-6.0-marshmallow

16
推荐指数
2
解决办法
1万
查看次数