2014-04-12 17 views
8

Ich habe eine vertikale LinearLayout innerhalb einer ScrollView. Alles war in Ordnung bis zur Einstellung der dritten TextView in LinearLayoutselectable.ScrollView automatisch scrollt auf wählbar TextView

Nach dieser Änderung scrollt es automatisch zum dritten TextView.

Was kann das Problem verursachen?

Vor und nach die Änderung:

enter image description hereenter image description here

das Layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/roota_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="right" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context="com.saliherikci.poemnotebook.ReadPoemActivity$PlaceholderFragment" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/poemTitleTextView" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Çanakkale Şehitlerine" 
       android:textColor="@color/poem_title" 
       android:textSize="24dp" /> 

      <TextView 
       android:id="@+id/poemAuthorTextView" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="5dp" 
       android:text="Mehmet Akif ERSOY" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textSize="11dp" /> 

      <TextView 
       android:id="@+id/poemContentTextView" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Şu Boğaz harbi nedir? Var mı ki dünyâda eşi? " 
       android:textColor="@color/poem_content" 
       android:textIsSelectable="true" 
       android:textSize="10dp" /> 
     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/fontSizeView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|right" 
     android:background="@color/font_size_background" 
     android:orientation="vertical" 
     android:paddingBottom="5dp" 
     android:paddingLeft="15dp" 
     android:paddingRight="15dp" 
     android:paddingTop="5dp" 
     android:visibility="invisible" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top|right" 
      android:text="YAZI BOYUTU" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#1a1a1a" 
      android:textSize="8dp" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top|right" 
      android:layout_marginTop="5dp" 
      android:dividerPadding="5dp" 
      android:orientation="horizontal" 
      android:showDividers="middle" > 

      <ImageButton 
       android:id="@+id/font_size_1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:background="@null" 
       android:src="@drawable/ic_font_size_black_1_active" /> 

      <ImageButton 
       android:id="@+id/font_size_2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_marginLeft="20dp" 
       android:background="@null" 
       android:src="@drawable/ic_font_size_black_2_inactive" /> 

      <ImageButton 
       android:id="@+id/font_size_3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_marginLeft="20dp" 
       android:background="@null" 
       android:src="@drawable/ic_font_size_black_3_inactive" /> 

      <ImageButton 
       android:id="@+id/font_size_4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_marginLeft="20dp" 
       android:background="@null" 
       android:src="@drawable/ic_font_size_black_4_inactive" /> 

      <ImageButton 
       android:id="@+id/font_size_5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dp" 
       android:background="@null" 
       android:src="@drawable/ic_font_size_black_5_inactive" /> 
     </LinearLayout> 
    </LinearLayout> 

</FrameLayout> 
+0

können Sie ausdrucken, was in Ihrem Layout XML-Datei ist? –

+0

Ich habe in Ihrem Layout-XML keine ScrollView gesehen. Haben Sie die ScrollView programmgesteuert hinzugefügt? –

+0

Hat den Code bearbeitet. –

Antwort

19

Sie automatisch an Ihre dritte TextView weil SrollView Scrollen macht einen Aufruf an ScrollView.scrollToChild upon ViewParent.requestChildFocus.

As per the docs is:

aufgerufen, wenn ein Kind dieser Eltern

konzentrieren will Wenn Sie android:textIsSelectable="true" verwenden, sind Sie im Wesentlichen TextView.setTextIsSelectable(true) Aufruf, die sowohl Anrufe View.setFocusable und View.setFocusableInTouchMode macht.

Kurz gesagt, zu stoppen von automatisch scrollen zu Ihrem dritten TextView, geben Sie den ersten Fokus.

<TextView 
    android:id="@+id/poemTitleTextView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:text="Çanakkale Şehitlerine" 
    android:textColor="@color/poem_title" 
    android:textSize="24dp" /> 
-2

Sie können versuchen, dieses Attribut von poemContentTextView (Ihre dritte Textview) zu entfernen?

android: layout_weight = "22.14"

+0

Ich habe es entfernt, es ist irrelevant für dieses Problem. –

-1

Dies ist meine Lösung:

@Override 
    protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) { 
     return 0; 
    } 
When called requestChildFocus will not called scrollToChild() 
Verwandte Themen