2012-02-10 96 views
0

我一直在试图开发一个包含可滚动活动 和活动内部的android应用程序,我有2个textView,我希望它们也可以滚动。Android textView滚动

我的问题是 每当我接触到的TextView的滚动显示出来,但它是LinearLayout中直接钢的焦点,不再TextView的滚动

我有办法的主要活动部分内,现在是建立为textView滚动XML文件我已经做到了。 如果我不断举起手指并将其放回屏幕上,试图滚动textView,我可以移动一点,但正如我所说的,包含textView的布局捕捉焦点并让我无法滚动textView。

我希望我很好地解释了我的问题。

请有任何建议来帮助。


让我解释应用程序是如何构建的第一 第一部分是:主(第一)活动是tabHost 我定义为滚动

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<ScrollView 
android:id="@+id/scrollView1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
<FrameLayout 
android:id="@android:id/tabcontent" 
android:layout_width="match_parent" 
android:layout_height="422dp" > 
</FrameLayout> 
<TabWidget 
android:id="@android:id/tabs" 
android:layout_width="match_parent" 
android:layout_height="63dp" > 
</TabWidget> 
</LinearLayout> 
</ScrollView> 
</TabHost> 

在那里我有问题是本次活动

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:background="@color/light_gray_color" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:weightSum="1" 
android:orientation="vertical" 

android:baselineAligned="false"> 

<LinearLayout 
android:id="@+id/linearLayout3" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_weight="0.04"> 

<TextView 
android:textAppearance="?android:attr/textAppearanceLarge" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:textColor="@color/black_color" 
android:layout_gravity="center_horizontal" 
android:text="@string/display_label" 
android:id="@+id/display_label"> 
</TextView> 

</LinearLayout> 


<LinearLayout 
android:id="@+id/linearLayout2" 
android:layout_width="match_parent" 
android:layout_height="0dp" 
android:layout_weight="0.83" 
android:baselineAligned="false" 
android:orientation="horizontal" > 


<ScrollView 
android:id="@+id/english_scrollView" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_weight="0.03" > 

<TextView 
android:id="@+id/display_english_textView" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="2px" 
android:layout_marginRight="2px" 
android:layout_weight="0.03" 
android:background="@drawable/black_rectangle" 
android:focusable="true" 
android:paddingLeft="2px" 
android:paddingRight="2px" 
android:scrollbars="vertical" 
android:textColor="@color/black_color" /> 

</ScrollView> 


<ScrollView 
android:id="@+id/translation_scrollView" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:layout_weight="0.03" > 

<TextView 
android:id="@+id/display_translation_textView" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="2px" 
android:layout_marginRight="2px" 
android:layout_weight="0.03" 
android:background="@drawable/black_rectangle" 
android:focusable="true" 
android:paddingLeft="2px" 
android:paddingRight="2px" 
android:scrollbars="vertical" 
android:textColor="@color/black_color" /> 

</ScrollView> 
</LinearLayout> 

</LinearLayout> 
+0

能否请您添加的代码,然后我们可以看到怎么回事,谢谢。 – FabianCook 2012-02-10 00:05:43

回答

0

我想你应该削减<ScrollView>出第一个XML的

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
<FrameLayout 
android:id="@android:id/tabcontent" 
android:layout_width="match_parent" 
android:layout_height="422dp" > 
</FrameLayout> 
<TabWidget 
android:id="@android:id/tabs" 
android:layout_width="match_parent" 
android:layout_height="63dp" > 
</TabWidget> 
</LinearLayout> 
</TabHost> 
+0

那么,谢谢你,但如果我遵循你的建议,那么应用程序中的所有活动将不会滚动? – Shakash3obd 2012-02-10 02:27:46

+0

嗯,你有没有尝试在第二个XML而不是第一个XML中添加ScrollView呢?无论如何,结果可能是一样的。这可能是关于设置可聚焦的真假,我不太了解。对不起,我没什么帮助。等待另一个答案:) – 2012-02-10 02:43:16

+0

不要担心。我试图把ScrollView放在那里,同时将ScrollView保留在第一个XML中,但这是问题所在。 我也试图做一些重点,如getFocus(),但由于我非常专业,我认为这并没有太大的作用。 谢谢:) – Shakash3obd 2012-02-10 02:51:26

0

我的理解是,你有一个垂直滚动的活动,其中包含两个垂直滚动的文本视图?如果是这样,你不能这样做。它不仅仅是一个糟糕的设计选择,它实际上不可能分辨出用户在滑动时想要滚动哪个视图。您可以在垂直滚动视图内进行水平滚动,反之亦然。垂直滚动内部的水平滚动或垂直滚动​​内不能水平滚动。

我相信这是在2010年的谷歌列表视图谈话IO会议中提到:http://www.youtube.com/watch?v=wDBM6wVEO70