2012-02-10 84 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