0

我一直在尝试开发一个 android 应用程序,其中包含一个可滚动的活动,并且在活动内部,我有 2 个 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>
4

2 回答 2

0

我的理解是你有一个垂直滚动的活动,它包含两个垂直滚动的文本视图?如果是这样,你不能这样做。它不仅仅是一个糟糕的设计选择,当用户进行滑动动作时,它实际上无法判断用户打算滚动哪个视图。您可以在垂直滚动视图中进行水平滚动,反之亦然。您不能在水平滚动中进行水平滚动,也不能在垂直滚动中进行垂直滚动。

我相信在 2010 年 google io 会议的 listview 演讲中提到了这一点:http ://www.youtube.com/watch?v=wDBM6wVEO70

于 2012-02-10T08:03:31.933 回答
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>
于 2012-02-10T02:17:28.590 回答