标签: android-scrollview

应用程序启动时读取布局大小

我需要ScrollView在活动启动期间检索布局xml文件中定义的高度.哪个是实现此目的的最佳实践.我试过把代码放在里面onCreate(),onStart()然后onResume().All在启动时将高度设为0.是否有像活动一样onFinishInflate()的方法?

这是我的代码:

myScroll=(ScrollView) findViewById(R.id.ScrollView01);
int height=myScroll.getHeight();
Run Code Online (Sandbox Code Playgroud)

android android-layout android-scrollview

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

ScrollView中的WebView似乎工作正常,但警告不使用 - 替代?

我读过的所有东西(在已经制作我的app :()后面写着"你永远不应该在ScrollView中使用WebView!".这是可以理解的,因为理论上你可以有两个滚动的东西,这将使奇怪的可用性.

但是 - 到目前为止,我没有看到任何不利影响.然后,我正在使用的每个WebView都不需要滚动 - 也许这使得它可以接受 - 即使它在技术上是错误的吗?

是否有不良影响,我只是没有注意到对特定版本的测试缺乏?

如果我不能在ScrollView中使用WebView,我将如何获得以下布局(我当前的应用程序):

LinearLayout
    ScrollView
        LinearLayout
            TextView //Title of article
            TextView //Subtitle of article
            RelativeLayout
                ImageView //Large Image (clickable to gallery)
                ImageView //"more photos icon"
            WebView // a small horizontal ad
            TextView // actual article text
            WebView //embedded HTML code ranging from iframe to video...etc
            WebView //embedded HTML code ranging from iframe to video...etc
            WebView // a small horizontal ad
            LinearLayout
                TextView //DB-driven "similar articles" list
            WebView //disqus comments
Run Code Online (Sandbox Code Playgroud)

注意:我意识到这是"错误的" - 但 …

android android-webview android-scrollview

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

Android - ScrollView内部的WebView在底部留下空白区域

我想在滚动容器中添加多个WebView.为了做到这一点,我在LinearLayout中以编程方式添加它们.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/scrollView"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

 <LinearLayout
        android:id="@+id/webViewContainer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        />

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

现在问题是当我使用loadDataWithBaseURL()方法在WebViews中加载数据时,WebViews在底部留下了一些额外的空间.无法为此问题找到合适的解决方案.谁能告诉我为什么会这样?

android android-webview android-scrollview

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

使用ScrollView中的onTouchListener检测滑动

我正在使用以下代码检测我的Activity中的滑动:

getWindow().getDecorView().getRootView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                if(action == MotionEvent.ACTION_DOWN){

                    downX = event.getX();
                    downY = event.getY();
                    //mSwipeDetected = Action.None;
                    return true; // allow other events like Click to be processed
                }
                else if(action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL){
                     upX = event.getX();
                     upY = event.getY();

                     float deltaX = downX - upX;
                     float deltaY = downY - upY;

                    // horizontal swipe detection
                    if (Math.abs(deltaX) > MIN_DISTANCE) {
                        // left or right
                        if …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-gesture

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

片段中的Recyclerview不会显示任何内容

我有一个片段,我想在其中包含recyclerview.但遗憾的是它没有显示任何内容,似乎查看器方法没有开始.(对不起,我的英语不好).这是片段的代码:

public class Quran_Fragment extends Fragment {

    public static final String ARG_SCROLL_Y = "ARG_SCROLL_Y";

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


        View view = inflater.inflate(R.layout.fragment_scrollview_quran, container, false);

      // Ab hier neu: Basem @ BMW

      RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);

      // Die Klasse ItemData_quran kann ja gleich bleiben für alle Fragments !! nur itemsData heisst dann anders....
      // Die Adapter, welche die verbindung zwischen Daten und Darstellung sind, werden fuer alle Fragments neu erzeugt: Quran_Fragment ->QuranAdapter, Translation_Fragment ->TranslationAdapter …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-scrollview android-viewholder android-recyclerview

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

滚动nestedscrollview到子recyclerview滚动之前结束

这是我的 layout

________________  ___   
|              |   ||
| Linear       |   ||
| Layout       |   ||
|              |   || nested scroll view
|______________|   ||
||            ||   ||
||            ||   ||
||   Child    ||  _||
||Recyclerview||
||____________||
|______________|      -end
Run Code Online (Sandbox Code Playgroud)

如何使父级LinearLayout先滚动,到达末尾时,子级recyclerview应该滚动。

默认情况下RecyclerView,在父级开始滚动之前,子级首先滚动到结尾。

android android-scrollview android-recyclerview nestedscrollview

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

是否可以将ScrollView添加到AppBarLayout

我需要和两个人一起工作ScrollView.一个在里面AppBarLayout,另一个在外面.

对于外界ScrollView,我使用的是NestedScrollViewappbar_scrolling_view_behavior它的工作正常.

对于里面,我使用的是Scrollviewapp:layout_scrollFlags="scroll|enterAlways|snap"

我的问题是,NestedScrollView似乎覆盖了ScrollView事件,即使我触摸该ScrollView区域,NestedScrollView也就是滚动的事件.

有什么办法可以吗?

请参阅以下代码:

<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">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/white"
            app:layout_scrollFlags="scroll|enterAlways|snap">

            <TextView                
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>  

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

     <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView                
               android:layout_width="match_parent"
               android:layout_height="wrap_content"/>   

    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-coordinatorlayout android-nestedscrollview

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

ViewPager中的ScrollView不会在Android 4.x上滚动

我有一个问题,似乎只影响Android 4.x版本,也可能是设备特定的(即我的华为G630@4.3上不存在,但确实存在于Samsung Ace2@4.4.4上).我有一个ScrollView包含RelativeLayout4 CardView秒的.现在在一些4.x设备上,当我尝试从卡片开始滚动时,滚动事件根本不会发生.如果我触摸卡之间的小填充或第一张卡之上(而不是任何两张之间)和设备屏幕,我可以滚动内容.

<?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:fillViewport="true">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/tools"
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="@dimen/activity_horizontal_margin">

        <android.support.v7.widget.CardView
            android:id="@+id/metricsContainerCard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:cardElevation="2dp"
            card_view:cardUseCompatPadding="true">

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

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

                    <ImageView
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="5dp"
                        android:src="@drawable/metrics"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/metrics"
                        android:textSize="20sp"/>
                </LinearLayout>


                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/projectCircleBackgroundShadow"/>

            </LinearLayout>

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

        <android.support.v7.widget.CardView
            android:id="@+id/warningsContainerCard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/metricsContainerCard"
            app:cardElevation="2dp"
            card_view:cardUseCompatPadding="true">

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

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

                    <ImageView
                        android:layout_width="20dp" …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-4.2-jelly-bean

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

当scrollview全屏滚动时,EditText失去焦点

我有聊天视图,具有滚动视图,包含文本视图,并在滚动视图上方编辑文本。当新消息打印到textview中时,滚动视图全滚动到结束。

activity.scrollView.post(new Runnable() {
            @Override
            public void run() {
                activity.scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            }
        });
Run Code Online (Sandbox Code Playgroud)

但是,如果我在EditText中键入文本,它将始终向下滚动并失去对编辑文本的关注(因此,如果消息经常打印,则键入message是不现实的)。我该如何解决?我在堆栈中找到了一些答案,但这并没有帮助我。就这个。

    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                scrollView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        scrollView.fullScroll(ScrollView.FOCUS_DOWN);
                    }
                }, 200);
            } else {
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

UPD:我的textview是scrollview的子级,具有属性

textView.setTextIsSelectable(true);
Run Code Online (Sandbox Code Playgroud)

我删除了该属性,现在可以了,我可以键入message并且自动滚动不会阻止我。但是它仍然质疑为什么会这样。另外,我仍然希望能够选择(复制)文本。

android focus android-edittext android-scrollview

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

CardView不滚动

下面是我的代码我有多个cardview内部LinearLayout但在构建后我无法滚动它.卡片视图的一半是隐藏的.

有一个屏幕截图

图片

我想滚动我的所有cardview.我试图添加,scrollview但它无法正常工作.添加后scrollview全部cardview不起作用

这是添加后发生的事情scrollview.

IAMGE2

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    tools:context="eras.ppt.ras.MainActivity"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@drawable/backgroundimage"
    android:gravity="center"
    android:id="@+id/ll">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="20dp"
        android:background="@color/transblue"/>

    <LinearLayout
        android:id="@+id/SliderDots"
        android:layout_below="@+id/viewPager"
        android:orientation="horizontal"
        android:gravity="center_vertical|center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </LinearLayout>


    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/physics"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpurple"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Physics"/>
                <View
                    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-scrollview cardview

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