2012-05-29 21 views
8

Sorun: ScrollView, belirli bir yüksekliğin ötesine büyüyünce, alt görünümünün üst kısmını gizler.ScrollView üst kısmı göstermiyor

ben düzeni aşağıdaki XML tanımladığınız

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:id="@+id/commandPanel" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:paddingLeft="5dip" 
     android:paddingRight="5dip" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="OK" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Back" /> 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/mainContentPanel" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/commandPanel" 
     android:background="@android:color/white" > 

     <ScrollView 
      android:id="@+id/formScrollView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" 
      android:layout_marginTop="5dip" 
      android:layout_weight="1" 
      android:background="@android:color/darker_gray" 
      android:fillViewport="false" 
      android:paddingBottom="5dip" 
      android:scrollbarStyle="insideOverlay" > 

      <LinearLayout 
       android:id="@+id/formContentLayout" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center" 
       android:layout_marginTop="20dip" 
       android:background="@android:color/black" 
       android:gravity="center_horizontal|top" 
       android:orientation="vertical" 
       android:paddingLeft="5dip" 
       android:paddingRight="5dip" 
       android:paddingTop="20dip" > 

       <LinearLayout 
        android:id="@+id/tr" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dip" 
        android:orientation="horizontal" > 

        <TextView 
         android:id="@+id/title" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="sample title" /> 

        <TextView 
         android:id="@+id/value" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="sample value ......." /> 
       </LinearLayout> 
      </LinearLayout> 
     </ScrollView> 
    </RelativeLayout> 

</RelativeLayout> 

---------- LinearLayout (scrollview acil kod ------

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.scrollview); 
    updateUi(); 
} 

//add few more rows here 
void updateUi() { 
    LinearLayout sampletr = (LinearLayout) findViewById(R.id.tr); 
    LinearLayout contentPane = (LinearLayout) findViewById(R.id.formContentLayout); 
    TextView title = (TextView) findViewById(R.id.title); 
    TextView value = (TextView) findViewById(R.id.value); 
    for (int i = 0; i < 25; i++) { 
     LinearLayout tr = new LinearLayout(this); 
     TextView t = new TextView(this); 
     t.setText("Sample title : " + i); 
     TextView v = new TextView(this); 
     v.setText("Sample value : " + i); 

     tr.addView(t, title.getLayoutParams()); 
     tr.addView(v, value.getLayoutParams()); 
     contentPane.addView(tr, sampletr.getLayoutParams()); 
    } 
} 

Burada üst sıraları çocuk) hayır ise yukarıdan kaybola başlar. satırların 15'den fazla büyür! Üstelik onları görüntülemek için el ile bile kaydırma yapamam, Herhangi bir işaretçi lütfen, bu düzende neyin var?

+0

ScrolView'da paddingBottom ayarlanmış olabilir misiniz? deneyin ve ne olduğunu görün. –

+0

@eric - herhangi bir fark yaratmıyor. – iuq

cevap

28

Tamam xml yazma, ben LinearLayout dan (scrollview derhal çocuğu)

android:layout_gravity="center" 
aşağıdaki satırı kaldırarak çözdük

ScrollView şimdi mükemmel çalışıyor. Öneri için herkese teşekkürler.

0

İkinci RelativeLayout düğümünü kaldırır ancak ScrollView'u saklayın. Daha sonra ScrollView için layout_alignParentTop=true ve layout_above="@+id/commandPanel" eklerim. Ikinci RelativeLayout gereksiz görünüyor ve genellikle RelativeLayout çocuklara eklediğinizde, kapsayıcının düzen seçeneklerini kullanmalıdırlar, örn., Layout_above, aşağıdaki, hizalama, vb.

0

sanki doldurma tepsiniz bir sorun gibi görünüyor önce kaldırmayı deneyin.

+0

kaldırma yastığı sorunu çözmedim ya – iuq

0

Jus lil değişikliği ile

<LinearLayout 
    android:id="@+id/commandPanel" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:paddingLeft="5dip" 
    android:paddingRight="5dip" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="OK" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Back" /> 
</LinearLayout> 

<RelativeLayout 
    android:id="@+id/mainContentPanel" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@id/commandPanel" 
    android:background="@android:color/white" > 

    <ScrollView 
     android:id="@+id/formScrollView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 

     android:layout_marginTop="0dp" <--- --- change n remove this margin 

     android:layout_weight="1" 
     android:background="@android:color/darker_gray" 
     android:fillViewport="false" 
     android:paddingBottom="5dip" 
     android:scrollbarStyle="insideOverlay" > 

     <LinearLayout 
      android:id="@+id/formContentLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" 
      android:layout_marginTop="20dip" 
      android:background="@android:color/black" 
      android:gravity="center_horizontal|top" 
      android:orientation="vertical" 
      android:paddingLeft="5dip" 
      android:paddingRight="5dip" 
      android:paddingTop="20dip" > 

      <LinearLayout 
       android:id="@+id/tr" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dip" 
       android:orientation="horizontal" > 

       <TextView 
        android:id="@+id/title" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="sample title" /> 

       <TextView 
        android:id="@+id/value" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:text="sample value ......." /> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 

+0

iyi Moto Quench (OS 2.1) üzerinde test ediyorum ve önerinizi denedim ama boşuna. – iuq