Подтвердить что ты не робот

Android scrollview скрывает верхний контент в макете

У меня возникла проблема, когда scrollview android начинает скрывать пару текстовых просмотров, которые у меня есть в верхней части моего макета, я нашел другого человека на этом самом сайте, у которого была эта проблема, и смог получить помощь, к сожалению, человеку, который помог они действительно не сказали, что это исправляет, может ли кто-нибудь сказать мне, в чем тут проблема?

андроид scrollview скрывает верхний контент

любая помощь будет огромной, вот мой 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>
4b9b3361

Ответ 1

Нашел! Это android:layout_gravity="center" в LinearLayout, которое является виновником. Просто удалите это, и все будет хорошо.

Ответ 2

Пробовали ли вы настройку

Android: fillViewport = "истина"

в 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" >

Ответ 3

Вы можете прокручивать программно.

  • Удалить свойство android: layout_gravity из xml
  • Добавить прокрутку в функцию onResume

Некоторый код из моего проекта:

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);
        }
    });
}

Ответ 4

Ваш внешний LinearLayout имеет высоту, установленную на match_parent. Он должен быть wrap_content. Внутренний LinearLayout должен также иметь высоту wrap_content.

Ответ 5

Добавьте андроид: layout_weight = "1" в ваш scrollview. Это решит проблему. Что-то вроде этого

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