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

ScrollView Layout не заполняет весь экран

Я получил Activity с двумя Fragment (один список один нормальный). И нормальный Fragment раздувает Scrollview, содержащий a LineaLayout (вертикальный), и этот макет содержит TextViews. Scrollview и layout_width и layout_height равны match_parent, поэтому я думаю, что весь экран должен использоваться. Но на дне еще есть "пробел". Надеюсь, ты поможешь мне.

ScrollView.xml

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/titlescreen_bg"
    android:orientation="vertical"
    android:paddingTop="60dp"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/tv_headline"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingBottom="60dp"
        android:paddingTop="60dp"
        android:textIsSelectable="false"
        android:textSize="@dimen/fontsize_slogan_titlescreen" />

    <TextView
        android:id="@+id/tv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:paddingBottom="30dp"
        android:paddingTop="30dp"
        android:textIsSelectable="false"
        android:textSize="@dimen/fontsize_slogan_titlescreen" />
</LinearLayout>

</ScrollView>

фрагмент, раздувающий этот макет.

package wak.iage.layout;

import wak.iage.R;
import android.app.Fragment;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MenuContentFragment extends Fragment
{
LinearLayout.LayoutParams   relativeParams  = new LinearLayout.LayoutParams(
                                                    LayoutParams.MATCH_PARENT,
                                                    LayoutParams.MATCH_PARENT);
LinearLayout                topLayout       = null;
TextView                    body            = null;
TextView                    head            = null;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.menu_content_main, container);
    return v;
}

public void changeText(String title, String content) {
    topLayout = (LinearLayout) getActivity().findViewById(
            R.id.LinearLayout1);
    head = (TextView) getActivity().findViewById(R.id.tv_headline);
    body = (TextView) getActivity().findViewById(R.id.tv_content);

    if (body == null) {
        topLayout.removeViews(1, topLayout.getChildCount() - 1);
        body = new TextView(getActivity().getApplicationContext());
        body.setPadding(0, 30, 0, 20);
        body.setTextColor(Color.BLACK);
        body.setTextSize(22);
        body.setGravity(Gravity.CENTER_HORIZONTAL);
        topLayout.addView(body, relativeParams);
    }

    body.setText(content);
    head.setText(title);
}

public void addGlossary() {
    if (body != null) {
        topLayout.removeView(body);
    }

    int i = 0;

    for (int id : GLOSSARY) {
        TextView glossary = new TextView(getActivity()
                .getApplicationContext());
        glossary.setText(getString(id));
        glossary.setTextColor(Color.BLACK);
        if (i % 2 == 0) {
            glossary.setTypeface(Typeface.DEFAULT_BOLD);
            glossary.setTextSize(22);
            glossary.setPadding(0, 10, 0, 10);
        }
        topLayout.addView(glossary, relativeParams);
        i += 1;
    }
}

public static final int[]   GLOSSARY    = {
        R.string.GlossaryAndroidOSTitle, R.string.GlossaryAndroidOSContent,
        R.string.GlossaryAppTitle, R.string.GlossaryAppContent,
        R.string.GlossaryCloudTitle, R.string.GlossaryCloudContent,
        R.string.GlossaryDonwloadTitle, R.string.GlossaryDonwloadContent,
        R.string.GlossaryFacebookTitle, R.string.GlossaryFacebookContent,
        R.string.GlossaryGPSTitle, R.string.GlossaryGPSContent,
        R.string.GlossaryHomescreenTitle,
        R.string.GlossaryHomescreenContent, R.string.GlossaryPasswordTitle,
        R.string.GlossaryPasswordContent, R.string.GlossaryRouterTitle,
        R.string.GlossaryRouterContent, R.string.GlossarySDTitle,
        R.string.GlossaySDContent, R.string.GlossayStandbyTitle,
        R.string.GlossayStandbyContent, R.string.GlossaryTabletTitle,
        R.string.GlossaryTabletContent, R.string.GlossaryTouchscreenTitle,
        R.string.GlossaryTouchscreenContent, R.string.GlossayWidgetsTitle,
        R.string.GlossayWidgetsContent, R.string.GlossayWLANTitle,
        R.string.GlossayWLANContent };
}

Большое спасибо.

Изменить: даже пробой уже исправлен: android: fillViewPort = "true", я хочу показать вам проблему.

Но у меня недостаточно репутации, чтобы опубликовать картинку. Извините!

4b9b3361

Ответ 1

Если я не ошибаюсь, высота ViewGroup height (LinearLayout height в вашем случае), то есть (только) дочерний элемент внутри ScrollView, всегда интерпретируется как wrap_content, поскольку это содержимое может быть больше чем высота ScrollView (следовательно, полосы прокрутки).

Это также означает, что если содержимое меньше, содержимое ScrollView (дочерний элемент) может не растягиваться, чтобы заполнить экран.

Чтобы визуально помочь вам исправить это, мы должны увидеть скриншот вашей проблемы.

Возможно, установка android:fillViewport="true" в ScrollView исправит вашу проблему:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

Ответ 2

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:fadeScrollbars="false"
android:scrollbars="vertical" >

В вашем ScrollView добавьте атрибут ie. андроид: fillViewport = "истина"

Ответ 3

inflater.inflate(R.layout.menu_content_main, container);

должен быть

inflater.inflate(R.layout.menu_content_main, container, false);