Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法使滚动工作_Android_Scroll_Scrollview - Fatal编程技术网

Android 无法使滚动工作

Android 无法使滚动工作,android,scroll,scrollview,Android,Scroll,Scrollview,我试图使屏幕适合垂直方向的水平滚动,因为它不适合和不滚动伟大。我添加了一个滚动视图,其中包含线性布局的单个子视图以及我想要的视图。没有错误,但当我将手机转到水平方向时,它仍然不会滚动。我做错了什么?下面是我的XML 谢谢 <TextView android:text="test App" android:textSize="20dp" android:layout_gravity="center_horizontal" android:textColor="#FCFCFC" andr

我试图使屏幕适合垂直方向的水平滚动,因为它不适合和不滚动伟大。我添加了一个滚动视图,其中包含线性布局的单个子视图以及我想要的视图。没有错误,但当我将手机转到水平方向时,它仍然不会滚动。我做错了什么?下面是我的XML

谢谢

<TextView 
android:text="test App" 
android:textSize="20dp"
android:layout_gravity="center_horizontal"
android:textColor="#FCFCFC" 
android:id="@+id/textView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
></TextView>

<TextView 
android:text="" 
android:textSize="20dp"
android:layout_gravity="center_horizontal"
android:textColor="#FCFCFC" 
android:id="@+id/textView3" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
></TextView>


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

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



<TextView 
android:text="Last Name" 
android:textSize="15dp"
android:id="@+id/textView4" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textColor="#FCFCFC"
android:singleLine="true"
></TextView>



<EditText 
android:layout_width="fill_parent" 
android:id="@+id/editText1" 
android:layout_height="wrap_content" 
android:text=""
android:singleLine="true"
></EditText>


<TextView 
android:text="" 
android:textSize="10dp"
android:layout_gravity="center_horizontal"
android:id="@+id/textView5" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
></TextView>


<TextView 
android:text="First Name"
android:textSize="15dp"
android:id="@+id/textView6" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textColor="#FCFCFC"
android:singleLine="true"
></TextView>

<EditText 
android:layout_width="fill_parent" 
android:id="@+id/editText2" 
android:layout_height="wrap_content" 
android:text=""
android:textSize="20dp"
android:singleLine="true"
></EditText>


<TextView 
android:layout_gravity="center_horizontal" 
android:text=""
android:textSize="15dp"
android:layout_width="wrap_content" 
android:id="@+id/TextView01" 
android:layout_height="wrap_content"
></TextView>

<TextView 
android:text="Description" 
android:textSize="15dp"
android:id="@+id/textView4" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textColor="#FCFCFC"
android:singleLine="true"
></TextView>


 <EditText 
android:layout_width="fill_parent" 
android:id="@+id/editText1" 
android:layout_height="wrap_content" 
android:text=""
android:textSize="15dp"
android:singleLine="false"
android:lines="10"
></EditText>



</LinearLayout>
</ScrollView>




<TextView 
android:layout_gravity="center_horizontal" 
android:text="" 
android:id="@+id/TextView02" 
android:textColor="#FCFCFC" 
android:textSize="5dp" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content"
></TextView>


<Button 
android:text="Next"
android:textSize="20dp"
android:layout_gravity="center_horizontal"
android:id="@+id/nextpage" 
android:layout_width="150dp" 
android:layout_height="60dp"
android:layout_alignParentBottom="true"
></Button>



是否尝试水平滚动滚动滚动视图?根据API(),滚动视图只能垂直工作。您可能必须编写自己的水平滚动的ScrollView实现。

您必须使用
HorizontalScrollView
进行水平滚动

您的
ScrollView
并且它的内容总是相同大小。视图布局不注意它在屏幕上是否可见。目前,布局中最后一个
TextView
按钮也可能隐藏在lanscape模式下(我假设所有这些都包装在根
LinearLayout
中,因为根标记丢失)。
ScrollView
简单地说,“如果我的内容比我大,我会滚动它们”

你应该考虑一个布局,其中顶部元素挂在顶部,底部两个元素挂在底部,ScReVIEW填充其间的空间。这样,当涉及到横向视图时,视图将更小,并且内容将在其中开始滚动

以下是我认为您想要的:)


我认为在这种情况下,您的400dp高度是不必要的,因为底部元素将挂在屏幕底部,而不是您需要一个固定的高度来隔开它们。但是,如果它仍然相关,则将其放在
滚动视图
内部的
线性布局
,而不是
滚动视图
本身。这是整个布局,顺便说一句。不要插入任何内容

如果这不是你想要的,希望它能让你走上正确的道路:)

希望有帮助


    <ScrollView 
    android:id="@+id/scrllvwNo1" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content">
    <HorizontalScrollView 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content">        
             <TextView
             android:id="@+id/text"
             android:text="your text"
             android:gravity="center"
             android:background="#0000aa"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"/>        
    </HorizontalScrollView> 
    </ScrollView>       

我认为您需要的是
android:isScrollContainer
xml元素。将此设置为true,并在
android:scrollbars
android:scrollbarStyle
中定义滚动条。开发者文档说这是为了适应输入法,但我发现它的作用不止于此。

这似乎是应该自动发生的事情。我的布局垂直,但当我打开手机时太长了。我只是希望它滚动,因为我有一个按钮在底部的布局。现在我必须写一堆代码来实现这一点?似乎不正确。忘记了
HorizontalScrollView
的存在,愚蠢的我。不过我还是有点困惑。你说你在底部有一个按钮。。。当您的手机处于横向模式时,是否要进行垂直滚动?您可能需要尝试更改线性布局的高度以包装内容。就目前而言,它将与ScrollView的高度相匹配,这样就没有足够的空间显示LinearLayout中的所有内容。我认为这太让屏幕水平滚动了。当手机水平放置时,我想让它垂直滚动。这就是我想做的。但当我打开电话时,它不工作。屏幕外的内容保留在那里,我无法在滚动视图中删除“400dp”定义的高度。使其
匹配父项
    <ScrollView 
    android:id="@+id/scrllvwNo1" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content">
    <HorizontalScrollView 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content">        
             <TextView
             android:id="@+id/text"
             android:text="your text"
             android:gravity="center"
             android:background="#0000aa"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"/>        
    </HorizontalScrollView> 
    </ScrollView>