2013-12-13 59 views
-1

我動態添加視圖像這樣的動態添加觀點:缺少滾動條

  LayoutInflater layoutInflater = 
      (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      final View addView = layoutInflater.inflate(R.layout.dynamicabout, null); 
      TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent); 
      textOut.setText(strings.get(index)); 
      ((ViewGroup) v).addView(addView); 

然而,一旦我們到達屏幕的底部和超越,沒有滾動條。 我嘗試過使用ScrollView,但是它沒有做任何事情。

dynamicabout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/aboutcontent" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:autoLink="all"/> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

about.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="@dimen/stdpadding" 
    android:paddingRight="@dimen/stdpadding" 
    android:paddingBottom="@dimen/stdpadding" 
    android:paddingTop="@dimen/stdpadding" 
    android:orientation="vertical" > 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     </ScrollView> 
</LinearLayout> 

回答

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="@dimen/stdpadding" 
    android:paddingRight="@dimen/stdpadding" 
    android:paddingBottom="@dimen/stdpadding" 
    android:paddingTop="@dimen/stdpadding" 
    android:orientation="vertical" > 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
<LinearLayout 
android:id="@+id/linear 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     </ScrollView> 
</LinearLayout> 

/////////////////////// /////

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/aboutcontent" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:autoLink="all"/> 
     </LinearLayout> 


</RelativeLayout> 

////////////////////////////////////// ////////////////////////

LinearLayout linear=(LinearLayout)findviewbyId(R.id.linear); 
LayoutInflater layoutInflater = 
      (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      final View addView = layoutInflater.inflate(R.layout.dynamicabout, null); 
      TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent); 
      textOut.setText(strings.get(index)); 
linearview.addView(addView); 

請清潔香港這個代碼:

+0

我偷懶的一面感謝你寫出來給我:D –

+0

歡迎...:).... – dipali

1

你需要做的是你需要有父母與子女視圖。將孩子添加到父級。 Parent是LinearBayout,位於dynamicabout.xml的ScrollView中。孩子是關於XML的。在運行時充滿XML,並將其添加到父視圖(ScrollView中的LinearLayout)。

P.S. >爲了能夠添加視圖內的父佈局設置一個ID,據我所知,它沒有ID。