2013-10-17 3 views
0

나는 동적으로 이미지를 포함하고있는 뷰를 만들고 있는데,이 뷰는 ViewFlipper에 추가됩니다. 이 문제는 스크롤바가 항상 보이도록 요구하는 것처럼 작동합니다. 그러나 간단하게 작동하지 못하고 내가 잘못하고 있는지 확실하지 않습니다. 다음은 android - 항상 프로그램 적으로 보여줄 스크롤바 가져 오기

내 동적 코드와 내가 어떻게 같은 ScrollView를 사용하려고에 대한 프로그래밍 방식

<TextView 
    android:id="@+id/txtStoryText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imgStoryLine" 
    android:layout_above="@+id/footer" 
    android:layout_margin="20dp" 
    android:scrollbars="vertical" 
    android:scrollbarSize="10dp" 
    android:fadeScrollbars="false" 
    android:textColor="@color/orange" 
    android:text="" /> 

답변

1

을 복제하는 것을 시도하고있다

for(int i = 0; i < 5; i++) 
{ 
    // Creating my linear layouts & views 
    lls = new LinearLayout(this); 
    llv = new LinearLayout(this); 
    lls.setOrientation(LinearLayout.VERTICAL); 

    // Adding image view 
    imgStory = new ImageView(this); 
    imgStory.setImageResource(GetImage(i)); 
    imgStory.setLayoutParams(new LayoutParams(width, width)); 
    lls.addView(imgStory); 

    // adding textview, which is scrollable 
    txtStory = new TextView(this); 
    txtStory.setText(unescape(story.get(i))); 
    txtStory.setTextColor(getResources().getColor(R.color.orange)); 
    txtStory.setPadding((int)padding, (int)padding, (int)padding, (int)padding); 
    txtStory.setMovementMethod(new ScrollingMovementMethod()); 
    //txtStory.setVerticalScrollBarEnabled(true); 
    //txtStory.setVerticalFadingEdgeEnabled(false); 
    lls.addView(txtStory); 

    // Adding views to my view flipper 
    llv.addView(lls); 
    viewFlipper.addView(llv, i); 
} 

XML 코드를 복제하는 것을 시도하고있다 XML 코드입니다 최상위 부모. 그래서,이 같은 일이 :

// Creating my linear layouts & views 
    lls = new ScrollView(this); // This wraps your textView 
    llv = new LinearLayout(this); 
    lls.setOrientation(LinearLayout.VERTICAL); 

참고 :이이 테스트되지 않은 상태입니다

// Creating my linear layouts & views 
lls = new LinearLayout(this); 
llv = new ScrollView(this); // This looks like the view you're adding to the viewFlipper 
lls.setOrientation(LinearLayout.VERTICAL); 

또는 당신이 스크롤하려는 단지 텍스트의 경우, 최초의 LinearLayout있는 ScrollView을합니다. 그냥 아이디어를 주려고. 이 기능을 사용하려면 ScrollView에 더 많은 레이아웃 매개 변수를 지정해야 할 수도 있습니다. 그들이 설정에 대한 얘기를 어디

또한 this post 좀 걸릴 수 있습니다 :

textView.setMovementMethod(new ScrollingMovementMethod()) 
+0

이 doesnit은 나를 TEH있는 ScrollView에 방향을 설정하는 것을 허용하지, 제대로 작동. 또한 이미지와 텍스트 뷰를 스크롤 할 수있게 만들 것입니다. 이상적으로는 ScrollView를 피하기를 좋아합니다. xml에서 볼 수 있듯이 완벽하게 작동했습니다. 감사. –

+0

나는 내 대답에서 언급 한 것처럼 TextView를 ScrollView에 랩핑 할 수 있습니다. 이것은 이론적으로 잘 작동하고 많은 두통을 줄여야합니다. 어쨌든, 당신이 그것을 이해하기를 바랍니다. – SBerg413

+0

업데이트 된 답변 setMovementMethod()를 사용할 수 있습니다. – SBerg413

관련 문제