标签: scrollview

是否可以在ScrollView中使用ViewPager?

我正在尝试使用一个ViewPager内部ScrollView,但ViewPager不会出现.如果我删除ScrollViewViewPager显示正常.

我用以下方法创建了一个简单的测试项目:

main.xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <android.support.v4.view.ViewPager
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:id="@+id/viewpager" />

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

活动类:

public class ScrollViewWithViewPagerActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
        vp.setAdapter(new MyPagerAdapter(this));
    }
}

class MyPagerAdapter extends PagerAdapter {

    private Context ctx;

    public MyPagerAdapter(Context context) {
        ctx = context;
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override …
Run Code Online (Sandbox Code Playgroud)

android scrollview android-viewpager

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

React Native:使用ScrollView时的垂直居中

我正在使用React Native,一旦我引入ScrollView,我就无法保留元素的垂直居中.为了演示,我使用React Native Playground创建了3个应用程序.所有示例都有2页,可以通过点击蓝色按钮来切换它们.

例1:

第一个示例显示了在第2页上垂直居中的块.这是因为容器已应用这些样式:

flex: 1,
flexDirection: 'column',
justifyContent: 'center',
Run Code Online (Sandbox Code Playgroud)

https://rnplay.org/apps/lb5wSQ

但是,一旦切换到第2页就会出现问题,因为页面的整个内容都不合适,所以我们需要一个ScrollView.

例2

在这个例子中,我将所有内容都包装在ScrollView中.这允许第2页滚动,但现在我丢失了第1页的垂直居中.

https://rnplay.org/apps/DCgOgA

例3

为了试图找回1的垂直居中,我申请flex: 1到了contentContainerStyle滚动型的.这修复了第1页的垂直居中,但我不再能够一直向下滚动到第2页的底部.

https://rnplay.org/apps/LSgbog

我如何解决这个问题,以便我在第1页上获得元素的垂直居中,但仍然可以让ScrollView一直滚动到第2页的底部?

scrollview react-native

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

滚动到滚动视图中的特定视图

我在scrollview中添加了一个scrollview和子项.在某些时候,我需要滚动到一个特定的视图.

<scrollview>

1. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

2. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

3. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

4. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

5. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

6. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

7. <linearlayout>

    <textview></textview>
    <textview></textview>

   </linearlayout>

   <button>
   </button>

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

上面的布局是动态创建的.所以我不能在这里发布xml文件.布局创建完全是动态的.甚至线性布局内的子视图的数量也可以变化.

所以,当我点击按钮时,我需要滚动到特定的视图说这里当我点击按钮时我需要滚动到线性布局4.我尝试使用scrollTo方法,但它滚动到滚动视图的顶部.

请提供一些建议.

android scrollview

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

停止ScrollView将焦点设置在EditText上

Android的ScrollView(当滚动或弹出时)喜欢设置EditText的焦点,当它是它的一个孩子时.滚动然后释放时会发生这种情况.反正有没有阻止这种行为?我已经尝试了几乎所有我能想到的东西以及我在StackOverflow上读过的所有内容.没有什么对我有用.下面是一个示例布局如果您想测试它.我迫切希望阻止这种愚蠢的行为.

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

<ScrollView 
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginRight="50dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    >

    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="100dp" 
        android:text="TestApp 1"
        />


    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="100dp" 
        android:text="Bleh...."
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />
    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="100dp" 
        android:text="TestApp 1"
        />


    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="TestApp 1"
        />

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="MeeEEEEEEEEEEEEE" …
Run Code Online (Sandbox Code Playgroud)

android focus scrollview android-edittext

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

在Android中更改滚动条颜色

是否可以在ScrollView或ListView中更改滚动条的颜色或外观?

android listview scrollview

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

MonoDroid:调用自定义视图的构造函数时出错 - TwoDScrollView

我正在构建一个Android应用程序,它使用在此处找到的自定义构建的TwoDScrollView:

http://blog.gorges.us/2010/06/android-two-dimensional-scrollview/

可以在其他几个网站上找到同一个类,Stack Overflow上的其他人也提出了有关它的问题.我在以前使用Java/Eclipse构建的Android应用程序中使用它,并且我取得了成功.

在我目前的应用程序中,我想使用C#和MonoDroid.我决定用C#重写整个TwoDScrollView类.在重写它,然后在一些布局XML中使用它之后,我在尝试运行我的代码时遇到以下异常:

抛出了System.NotSupportedException.无法从本机句柄44f4d310激活MyProject.TwoDScrollView类型的实例.

System.Exception:找不到MyProject.TwoDScrollView ::.ctor(System.IntPtr,Android.Runtime.JniHandleOwnership)......的构造函数......后面有更多文本....

我的布局XML如下:

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

<myproject.TwoDScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

</myproject.TwoDScrollView>

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

根据以下链接中有关在MonoDroid中使用布局XML中的自定义视图的说明:http://docs.xamarin.com/android/advanced_topics/using_custom_views_in_a_layout

TwoDScrollView类的构造函数如下所示:

public TwoDScrollView(Context context) 
    : base(context)
{
    initTwoDScrollView();
}

public TwoDScrollView(Context context, IAttributeSet attrs) 
    : base(context, attrs)
{
    initTwoDScrollView();
}

public TwoDScrollView(Context context, IAttributeSet attrs, int defStyle) 
    : base(context, attrs, defStyle)
{
    initTwoDScrollView();
}
Run Code Online (Sandbox Code Playgroud)

C#版本中存在与Java版本相同的构造函数(可以在上面的链接中找到).什么可能出错?如果有人想看,我可以发布我的TwoDScrollView的完整C#代码.除了用C#重写之外,它基本上与位的Java代码位相同.

谢谢你的帮助!

android scrollview android-custom-view android-layout xamarin.android

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

ScrollView不会滚动到底部

我的活动中有一些问题.ScrollView不会向下滚动到底部.
我有截图给你. 在此输入图像描述

如果查看scrollView的滚动条,可以看到它没有向下滚动到底部.
这是我的scrollView的XML布局:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:fillViewport="true"
    android:layout_below="@+id/step2_header" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" >

        <TextView
            android:id="@+id/step2_headerText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:gravity="center"
            android:text="@string/Schritt2"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/dark_blue"
            android:textStyle="bold|italic" />

        <ImageView
            android:id="@+id/step2_image"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_below="@+id/step2_headerText"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="10dp"
            android:src="@drawable/menu_leiste" />

        <TextView
            android:id="@+id/step2_infoText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/step2_image"
            android:text="@string/step2Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

       <ImageView
            android:id="@+id/step2_but1Img"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_below="@+id/step2_infoText"
            android:layout_marginTop="10dp"
            android:src="@drawable/menu_leiste_selector" />

        <TextView
            android:id="@+id/step2_but1Text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/step2_but1Img"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/step2_but1Img"
            android:layout_marginLeft="10dp"
            android:gravity="center"
            android:text="@string/step2But1Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white" />

        <ImageView
            android:id="@+id/step2_but1ArrowImg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="3dp"
            android:layout_alignBottom="@+id/step2_but1Img"
            android:layout_alignParentRight="true" …
Run Code Online (Sandbox Code Playgroud)

xml android scrollview

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

如何滚动scrollview中的edittext

我有一个scrollview里面有一个多行的editext .我想滚动edittext以查看较低的内容,但无法完成.

<?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="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_light"
        android:gravity="center" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="View Complaint"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:padding="20dp" >
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="Order Number 0100C1"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Name of ClientClient 1"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Subject : Measurement Issues"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dp"
                android:text="Description"
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textView6" …
Run Code Online (Sandbox Code Playgroud)

user-interface android scrollview

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

iOS ScrollView需要约束y位置或高度

-ViewController
--View
---ScrollView (Top,Bottom,Leading,Trailing spaces to superview set to 0)
----ContentView (Top,Bottom,Leading,Trailing spaces to superview set to 0, Width equals with View (ViewController's child))
-----Label1
-----etc...
Run Code Online (Sandbox Code Playgroud)

如果我为我的内容视图设置了一个特定的高度约束(例如1000),ScrollView工作正常,但我有一个1000的静态ContentView,这不是我的目标,因为我的contentView获得了动态内容,所以应该是内容的高度需要.

如果我删除了ContentView的高度约束,Xcode说:

Missing Constraints:
ScrollView need constraints for: Y position or height
Run Code Online (Sandbox Code Playgroud)

ScrollView实际上是固定在顶部和底部,所以我不知道为什么Xcode想要ScrollView的高度约束...

当我希望ContentView高度达到内容所需的高度时,正确的方法是怎样的?

objective-c scrollview storyboard ios autolayout

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

活动开始时,OnScreen键盘自动打开

当我的活动ScrollView布局和EditTexts开始时,EditTexts得到焦点并且Android OnScreen键盘打开.

我怎么能避免这种情况?

当我使用LinearLayoutRelativeLayout没有ScrollView它时,它不会发生.

我已经尝试过这种方式了,但它确实有效,但这不是一个好方法:

TextView TextFocus = (TextView) findViewById(R.id.MovileLabel);
TextFocus.setFocusableInTouchMode(true);
TextFocus.requestFocus();
Run Code Online (Sandbox Code Playgroud)

接下来你有一些我的布局有这个问题的例子,当这个Activity开始时,焦点转到第一个EditText,描述和Android键盘自动打开,这非常烦人.

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

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:padding="10px">

        <RelativeLayout
            android:gravity="center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/UserLabel" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="13px"
                android:text="@string/userlabel"/>
            <TextView
                android:id="@+id/User"
                android:layout_alignBaseline="@id/UserLabel"
                android:layout_alignParentRight="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="test"/>
        </RelativeLayout>

        <View
            android:layout_gravity="center_horizontal"
            android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:background="#808080"
            android:layout_marginTop="5px"
            android:layout_marginBottom="12px"/>

        <RelativeLayout
            android:gravity="center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
            android:id="@+id/DescriptionLabel" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/desclabel"
            android:layout_marginTop="13px"/>
            <EditText 
            android:id="@+id/Description"
            android:layout_alignBaseline="@id/DescriptionLabel" …
Run Code Online (Sandbox Code Playgroud)

keyboard android focus scrollview

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