标签: android-scrollview

NestedScrollView 中的 CardView 自动增加高度 [包含图像]

我正在嵌套滚动视图中添加卡片。对于 LinearLayout 中顺序较低的卡片,卡片高度会自动增加。要了解该问题,请注意第一张卡片和最后一张卡片之间的卡片高度。尽管卡片相同,但最后一张卡片的阴影比第一张卡片的阴影更深。如何解决?

使用 appcompat v7:22.+ 作为 v7 库的依赖项。

这是我的卡片视图布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardElevation="1dp"
    android:layout_marginBottom="10dp"
    card_view:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_margin="10dp"
            xmlns:android="http://schemas.android.com/apk/res/android">

            <TextView
                android:id="@+id/hint"
                android:layout_width="0dp"
                android:text="ABC"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textColor="@color/textHint"/>
            <TextView
                android:id="@+id/description"
                android:layout_width="0dp"
                android:text="DEFG BHJHKJ"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"/>
        </LinearLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

这就是我使用卡片视图的方式:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingtoolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include
                layout="@layout/shared_activity_item"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:contentInsetStart="0dp"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-cardview android-elevation nestedscrollview

5
推荐指数
0
解决办法
1598
查看次数

同一滚动下的水平和垂直 RecyclerView

我必须做一些像 Instagram 那样的事情。我有一个用于故事的水平 RecyclerView,下面是一个用于提要的垂直 RecyclerView。我想完成相同的滚动行为(故事应该在滚动时与提要一起进行,而不是固定在顶部)。我找到的唯一解决方案是 NestedScrollView 但它使 RecyclerViews 的性能极其糟糕,我的屏幕几乎永远冻结。我尝试了很多在这里找到的技巧,如nestedScrollEnabled、autoLayoutMeasure 等,但没有任何效果。谢谢。

android android-scrollview instagram android-recyclerview android-nestedscrollview

5
推荐指数
1
解决办法
3050
查看次数

CoordinatorLayout - 向相反方向投掷会导致抖动

我需要在顶部制作一个带有静态视图的可滚动片段,并在底部的每个页面中制作一个带有 RecyclerView 的 ViewPager。我正在尝试使用 CoordinatorLayout 来实现预期的结果,但遇到了一个问题 -当我向上翻转顶部视图(为了向下滚动)并且在向下翻转 RecyclerView 之后(为了向上滚动),滚动是好的抵消和抖动;当我第一次将 Recycler View 向下翻转然后将顶部视图向上翻转时,整个片段会滚动回顶部。当我开始向相反方向滚动时,滚动看起来像是继续而不是停止。

我找到了一个具有类似布局(code的教程,但是在尝试之后,我发现它遇到了同样的问题。

以下是问题记录:

编辑:在下面添加了布局代码

fragment_layout.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
?
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    >
    ?
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/main.collapsing"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        app:layout_scrollFlags="scroll|snap"
        >
        ?
        <ImageView
            android:id="@+id/materialup.profile_backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/picture300x300"
            app:layout_collapseMode="parallax"
            />
    </android.support.design.widget.CollapsingToolbarLayout>
    ??
    <android.support.v7.widget.Toolbar
        android:id="@+id/materialup.toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="24dp"
        app:theme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        style="@style/Widget.AppCompat.Toolbar"
        />
    ?
    <LinearLayout
        android:id="@+id/materialup.title_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="8dp"
        android:gravity="center" …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview coordinator-layout android-coordinatorlayout android-nestedscrollview

5
推荐指数
1
解决办法
350
查看次数

Android NestedScrollView TalkBack - 仅导航到屏幕上可见的项目,跳过滚动下方的元素并转到底部选项卡

我的屏幕上有一个嵌套滚动条,占据了屏幕的 90%,还有一个固定的底部选项卡。我正在研究屏幕上的辅助功能,但遇到了一个问题:只要每个项目在屏幕上可见,TalkBack 就会正确导航到它们。一旦您到达可见项目的底部并尝试滑动以转到下一个项目,滚动视图就会滚动,但 TalkBack 焦点会跳转到固定在屏幕上的底部选项卡,从而绕过所有新的可见项目。

有什么设置或者我缺少什么吗?滚动视图内的项目对于可访问性都很重要,如果我将屏幕设置为将它们显示在屏幕上,TalkBack 的导航会击中它们并正确读取它们。

谢谢

android accessibility android-scrollview talkback

5
推荐指数
1
解决办法
1857
查看次数

带有 ConstraintLayout 的 BottomSheetDialog 包含 NestedScrollView,其高度 match_constraint 渲染为实际 0px 高度

我有一个非常简单的布局,需要将其渲染为BottomSheetDialog. 布局只是一个滚动视图,仅包含TextViews 和下面的一个按钮一个按钮(因此该按钮固定在底部并且始终可见。)\n这只是我的应用程序中内容的精炼版本,但它会足以说明问题:

\n
<?xml version="1.0" encoding="utf-8"?>\n<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"\n    xmlns:app="http://schemas.android.com/apk/res-auto"\n    android:layout_height="match_parent"\n    android:layout_width="match_parent">\n\n    <androidx.constraintlayout.widget.ConstraintLayout\n        android:layout_width="match_parent"\n        android:layout_height="match_parent">\n\n        <androidx.core.widget.NestedScrollView\n            android:id="@+id/nestedScrollView"\n            android:fillViewport="true"\n            android:layout_width="0dp"\n            android:layout_height="0dp"\n            android:layout_marginBottom="16dp"\n            app:layout_constraintBottom_toTopOf="@id/ok_button"\n            app:layout_constraintEnd_toEndOf="parent"\n            app:layout_constraintStart_toStartOf="parent"\n            app:layout_constraintTop_toTopOf="parent">\n\n        <androidx.constraintlayout.widget.ConstraintLayout\n            android:layout_width="match_parent"\n            android:layout_height="match_parent">\n\n                <TextView\n                    android:id="@+id/fine_print_header"\n                    android:layout_width="match_parent"\n                    android:layout_height="wrap_content"\n                    android:layout_marginStart="16dp"\n                    android:layout_marginLeft="16dp"\n                    android:layout_marginTop="32dp"\n                    android:layout_marginEnd="16dp"\n                    android:gravity="center_horizontal"\n                    android:text="Fine Print"\n                    app:layout_constraintEnd_toEndOf="parent"\n                    app:layout_constraintStart_toStartOf="parent"\n                    app:layout_constraintTop_toTopOf="parent" />\n\n                <TextView\n                    android:id="@+id/fine_print_copy"\n                    android:layout_width="match_parent"\n                    android:layout_height="wrap_content"\n                    android:layout_marginStart="16dp"\n                    android:layout_marginLeft="16dp"\n                    android:layout_marginTop="32dp"\n                    android:layout_marginEnd="16dp"\n                    android:text="This is the fine print. It\'s very detailed. So many carefully crafted details"\n                    app:layout_constraintEnd_toEndOf="parent"\n                    app:layout_constraintStart_toStartOf="parent"\n                    app:layout_constraintTop_toBottomOf="@id/fine_print_header"/>\n\n            </androidx.constraintlayout.widget.ConstraintLayout>\n        </androidx.core.widget.NestedScrollView>\n        <Button\n            android:id="@+id/ok_button"\n            android:layout_width="0dp"\n            android:layout_height="wrap_content"\n            android:layout_marginHorizontal="16dp"\n            android:layout_marginVertical="16dp"\n …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-constraintlayout android-bottomsheetdialog

5
推荐指数
0
解决办法
1337
查看次数

将动态线性布局添加到当前视图android

我试图在scrollview中添加一个linearlayout这是代码编译的代码,但它没有向我显示新的布局

这是原始布局(我想添加到它)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" 

android:layout_margin="15dp"
android:layout_marginTop="15dp">

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" 
     android:id="@+id/ViewHistoryImageLayout">

    <ImageView
        android:id="@+id/HistoryImage"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.76"
        android:gravity="center"
        android:padding="10dp"
        android:src="@drawable/upload" 
        android:contentDescription="@string/HistoryImage"/>

    <TextView
        android:id="@+id/TranslatedText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.12"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/translateImageButton" />

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

这是我想多次添加的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/TranslationMenuLayout" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<RatingBar
    android:id="@+id/ratingBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:numStars="5" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="TextView" />

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

并且用于添加新布局的java代码是:

setContentView(R.layout.activity_view_history_image);
ScrollView sv = new ScrollView(this);
LayoutInflater inflater = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout android-scrollview

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

Android Autoscroll imageview

在我的活动中,我只有一个ImageView.在其中,src是比屏幕大很多的图片.我希望图片从左到右缓慢滚动,直到它到达照片的右边缘,然后开始向左滚动,直到达到左边距.然后重新开始.我需要它在一个单独的线程中发生,这样手机就不会在发生这种情况时冻结. 这就是我需要的

我怎样才能做到这一点?是否有一个小部件默认执行此操作?

更新的代码 //布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mylinear"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="center"
        android:src="@drawable/rainforest" />

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

//和活动

public class MainActivity extends Activity {

    Animation           _translateAnimation;
    RelativeLayout        _relativeLoading = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        _translateAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, -100f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
        _translateAnimation.setDuration(5000);
        _translateAnimation.setRepeatCount(-1);
        _translateAnimation.setRepeatMode(Animation.REVERSE); // REVERSE
        _translateAnimation.setInterpolator(new LinearInterpolator());
        _relativeLoading = (RelativeLayout) findViewById(R.id.mylinear);
        _relativeLoading.startAnimation(_translateAnimation);
    }
Run Code Online (Sandbox Code Playgroud)

但它没有了.我的意思是,滚动从左到右,将图片"推"到左边,并在ImageView下显示白色背景.

  • 此外,这应该在一个线程或什么?我需要能够以某种方式退出这个"滚动"活动,而不使用"后退"按钮.我想要一个ImageView顶部的按钮(按钮应保持静止)和onClick它应该启动另一个Intent

  • 似乎ImageView中的图片被裁剪为适合屏幕内部.我怎么能克服这个?

android android-imageview android-scrollview

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

列表视图滚动不平滑

我有一个自定义列表视图,显示用户,并有照片我从API检索数据,提供JSON输出,

我的问题是列表视图不能平滑滚动,它会挂起一秒钟并滚动,它会重复相同直到我们到达终点.

我认为这可能是因为我在UI线程上运行网络相关操作,但即使在完成加载后它仍然继续这样做?

我的自定义Listview的结构是

 <TextView  style="@style/photo_post_text"
             android:id="@+id/photo_post_text"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="demotext"
           />


        <ImageView
            android:id="@+id/userimage"
           android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"

            android:adjustViewBounds="true"
           android:src="@drawable/pi" 
           />
Run Code Online (Sandbox Code Playgroud)

android android-listview android-scrollview android-scroll

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

在android listview中使用onScroll

朋友我正在使用listview并在滚动结束时滚动加载内容.但我面临的错误就像同一个url被多次调用一样,如果快速滚动,任何人都可以帮我解决这个问题.我已经走了SCROLL_STATE_IDLE,但不知道如何在我的代码中实现相同的.即使我没有触摸它的运行屏幕.我现在想知道如何在空闲状态下停止代码.在下面找到我的代码

int start = 0;
int limit = 3;
loadingMore = false;
listView.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
                            }

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            // TODO Auto-generated method stub
            int lastInScreen = firstVisibleItem + visibleItemCount;


            if ((lastInScreen == totalItemCount) ) {

                if(loadingMore == false){                   
                start = lastInScreen - 1;                   
                url = "http://www.dskjhf.com/web-servic/request_response.php?type=get_articles&start="
                        + start + "&end=" + limit;
                grabURL(url);                   
            }
        }}
    }); …
Run Code Online (Sandbox Code Playgroud)

android listview android-listview android-scrollview android-scroll

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

在RecyclerView android里面的ScrollView

我目前正在使用recyclerView和卡.

我有卡片布局.现在我想在卡片中添加scrollview是可能的.如果是,那怎么样?棕色布局是回收器视图布局,而蓝色布局是卡片布局.在每张卡内我需要一个scrollview是可能的吗?

在此输入图像描述

android android-scrollview android-cardview android-recyclerview

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