2012-03-28 20 views
31

Mam problem z miejscem, w którym zaczyna się przewijanie androida, ukrywając parę widoków tekstu, które mam na górze mojego układu, znalazłem inną osobę na tej stronie, która miała ten problem i była w stanie uzyskać pomoc, niestety osoba, która im pomogła, nie powiedziała, co to naprawia, czy ktoś może mi powiedzieć, co tu naprawiono?Android scrollview ukrywa najwyższą zawartość w układzie

android scrollview hiding top content

Każda pomoc będzie ogromny tu jest mój kodu xml:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/title_color_dark_transparent" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_vertical|center_horizontal|center" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="5dp" 
     android:orientation="vertical" 
     android:paddingTop="5dp" > 

     <TextView 
      android:id="@+id/saysomething" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/loading" 
      android:textColor="#FFFFFF" 
      android:textSize="30dp" /> 

     <TextView 
      android:id="@+id/saysomethinginfo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:text="@string/loading" 
      android:textColor="#FFFFFF" 
      android:textSize="17dp" /> 

     <EditText 
      android:id="@+id/tweetedittext" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/edit_text" 
      android:gravity="top" 
      android:hint="@string/edittext_hint" 
      android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete" 
      android:lines="3" 
      android:textAppearance="@style/TextAppearance.EditText" 
      android:textSize="17dp" /> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:orientation="horizontal" > 

      <Button 
       android:id="@+id/photobutton" 
       style="@style/TextAppearance.Button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/button_background" 
       android:onClick="photobuttonClicked" 
       android:text="@string/photobuttontext" 
       android:textSize="15dp" /> 

      <TextView 
       android:id="@+id/charactersremaining" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_centerInParent="true" 
       android:layout_toLeftOf="@+id/posttweetbutton" 
       android:text="@string/characters" 
       android:textColor="#FFFFFF" 
       android:textSize="20dp" /> 

      <Button 
       android:id="@id/posttweetbutton" 
       style="@style/TextAppearance.Button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_marginLeft="2dp" 
       android:background="@drawable/button_background" 
       android:onClick="posttweetbuttonClicked" 
       android:text="@string/postbuttonstext" 
       android:textSize="15dp" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/photodetails" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="" 
     android:textColor="#FFFFFF" 
     android:textSize="17dp" 
     android:layout_marginTop="8dp" 
     android:layout_marginLeft="8dp" /> 

    <ImageView 
     android:id="@+id/iv_pic" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" /> 
</LinearLayout> 

</ScrollView> 
+1

nie widzę żadnych TextView powyżej twój Scrollview. Brakuje Ci również tagu zamykającego w swoim ScrollView. – kabuko

+0

Wygląda na to, że błędnie nie komentowałem w tagu zamykającym dla przewijania, ale teraz tam jest, pierwsze odsłony są widoczne w układzie liniowym, umieszczanie odsłon poza układem liniowym daje mi błąd, ponieważ najwyraźniej nie masz więcej niż jedno dziecko w przewijanym widoku –

+0

Myślałem, że nie chcesz, aby Twój ScrollView ukrywał te widoki tekstowe? Może powinieneś wyjaśnić, jak naprawdę chcesz wyglądać, ponieważ nie jest to dla mnie jasne. – kabuko

Odpowiedz

92

Znaleziono! To jest android:layout_gravity="center" w LinearLayout, który jest winowajcą. Po prostu to usuń i wszystko powinno być w porządku.

+0

Dzięki za to - pracował dla mnie w wystąpienie tego problemu. –

+0

@Ddmund Rojas: Zaakceptuj poprawną odpowiedź. – Deepzz

+5

Działa, a jeśli nadal potrzebujesz wyśrodkować widok wewnątrz, użyj tego rozwiązania: http://pivotallabs.com/centrum-widoku-within-a-viewview/ – Takhion

0

Twój zewnętrzna LinearLayout jest jej wysokość ustawiona na match_parent. Zamiast tego powinno być wrap_content. Wewnętrzna LinearLayout powinna również mieć wysokość wrap_content.

+0

Próbowałem tego, ale niestety nie działało:/ –

0

Dodaj android: layout_weight = "1" do swojej przewijania. To rozwiąże problem. Coś podobnego to

<ScrollView 
     android:id="@+id/scroll" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1" > 
3

Czy próbowałeś ustawienie

android: fillViewport = "true"

w Scrollview?

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    android:background="@color/title_color_dark_transparent" > 
+0

To zadziałało, dzięki –

1

Program można przewijać.

  1. Usuń android: nieruchomość layout_gravity z xml
  2. Dodaj przewijanie do onResume funkcji

Niektóre kodu z mojego projektu:

protected void onResume() { 
    super.onResume(); 
    final HorizontalScrollView svInMenu = (HorizontalScrollView) findViewById(R.id.svInMenu); 
    ViewTreeObserver vto = svInMenu.getViewTreeObserver(); 
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
     public void onGlobalLayout() { 
      svInMenu.scrollTo(svInMenu.getRight()/4, 0); 
     } 
    }); 
} 
Powiązane problemy