将Scrollview添加到整个活动中

时间:2018-07-17 10:01:46

标签: java android

我想在整个活动中添加滚动视图。我希望​​对每个布局和视图都赋予权重,因为我希望屏幕是通用的。但是,通过在活动顶部添加滚动视图,可以使整个屏幕混乱,我看不到我所有的文字,在每件事之间都添加了额外的空格。我希望我已经清楚地陈述了我的问题,因为我对每种布局和视图都加了权重,而不是为什么改变了屏幕的视图,这确实让我很恼火。 我也看到已经在这里发布了相同问题的解决方案,但我对此并不满意。 我想要的只是在不影响布局和文本的情况下滚动整个活动的简单方法。 这是添加scrollview后我的活动的图像:

[ enter image description here

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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="match_parent"
    android:orientation="vertical"
    android:weightSum="3"
    android:background="@drawable/empty"
    tools:context=".story_activity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Story Name"
        android:textAlignment="center"
        android:textColor="#fff"
        android:layout_marginTop="5dp"
        android:textSize="20sp"
        android:textStyle="bold"></TextView>
       <!-- android:layout_marginLeft="140dp"-->/>

    <LinearLayout
        android:layout_marginTop="5dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:weightSum="3"
        android:background="@drawable/story_des"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="15dp"
        android:alpha="0.8"
        android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <ImageView
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/lion"/>

</LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1.3"
            android:weightSum="1.2"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="vertical">

            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scrollbars="none">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters."


                android:padding="15dp"

                android:textColor="#fff"
                android:textSize="15sp"
                android:id="@+id/story_content"/>
                <!--android:scrollbars = "vertical"-->
            </ScrollView>
            </LinearLayout>

            <LinearLayout

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:orientation="horizontal">
                <TextView

                    android:id="@+id/story_rate"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Rate This Story"
                    android:layout_gravity="center"
                    android:padding="5dp"
                    android:layout_marginLeft="10dp"
                    android:textSize="15sp"

                    android:textColor="#1e5aaa"
                    android:textStyle="bold"/>

                <ImageView
                    android:id="@+id/rate"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/story_rate"
                    android:src="@drawable/star"
                    android:layout_gravity="center"
                    />
                <ImageView
                    android:id="@+id/rate1"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/rate"
                    android:layout_gravity="center"
                    android:src="@drawable/star"
                    />
                <ImageView
                    android:id="@+id/rate2"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/rate1"
                    android:src="@drawable/star"
                    android:layout_gravity="center"
                    />
                <ImageView
                    android:id="@+id/rate3"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/rate2"
                    android:src="@drawable/star"
                    android:layout_gravity="center"
                    />
            </LinearLayout>

</LinearLayout>



<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:orientation="vertical">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:src="@drawable/line"/>
    <RelativeLayout
        android:layout_marginBottom="-90dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/author_image"
        android:layout_width="80dp"
        android:layout_height="60dp"

        android:layout_marginLeft="20dp"
        android:layout_marginBottom="20dp"
        android:src="@drawable/as" />


    <TextView
        android:id="@+id/author_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:layout_marginLeft="2dp"
        android:textSize="15dp"
        android:textColor="#fff"
        android:layout_toRightOf="@+id/author_image"
        android:fontFamily="century-gothic"

        android:text="Author Title"
        />
    <TextView
        android:id="@+id/pub_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:layout_marginTop="3dp"
        android:layout_toRightOf="@+id/author_image"
        android:layout_below="@+id/author_title"
        android:layout_marginLeft="2dp"
        android:textSize="15dp"
        android:textColor="#fff"
        android:fontFamily="century-gothic"
        android:text="Pve sentences, cjajsxa "
        />
    </RelativeLayout>

</LinearLayout>

</LinearLayout>
    </LinearLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:1)

删除weightSum和权重

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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"
        android:background="@drawable/empty"
        android:orientation="vertical"
        tools:context=".story_activity">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="Story Name"
            android:textAlignment="center"
            android:textColor="#fff"
            android:textSize="20sp"
            android:textStyle="bold"></TextView>
        <!-- android:layout_marginLeft="140dp"-->/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"
            android:alpha="0.8"
            android:background="@drawable/story_des"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="100dp"
                    android:layout_marginTop="10dp"
                    android:src="@drawable/lion" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/story_content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="15dp"
                        android:text="This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters."
                        android:textColor="#fff"
                        android:textSize="15sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.3"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/story_rate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="10dp"
                        android:padding="5dp"
                        android:text="Rate This Story"
                        android:textColor="#1e5aaa"
                        android:textSize="15sp"
                        android:textStyle="bold" />

                    <ImageView
                        android:id="@+id/rate"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/story_rate"
                        android:src="@drawable/star" />

                    <ImageView
                        android:id="@+id/rate1"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/rate"
                        android:src="@drawable/star" />

                    <ImageView
                        android:id="@+id/rate2"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/rate1"
                        android:src="@drawable/star" />

                    <ImageView
                        android:id="@+id/rate3"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/rate2"
                        android:src="@drawable/star" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="30dp"
                    android:src="@drawable/line" />

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/author_image"
                        android:layout_width="80dp"
                        android:layout_height="60dp"
                        android:layout_marginBottom="20dp"
                        android:layout_marginLeft="20dp"
                        android:src="@drawable/as" />

                    <TextView
                        android:id="@+id/author_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="2dp"
                        android:layout_toRightOf="@+id/author_image"
                        android:fontFamily="century-gothic"
                        android:text="Author Title"
                        android:textColor="#fff"
                        android:textSize="15dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/pub_content"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/author_title"
                        android:layout_marginLeft="2dp"
                        android:layout_marginTop="3dp"
                        android:layout_toRightOf="@+id/author_image"
                        android:fontFamily="century-gothic"
                        android:text="Pve sentences, cjajsxa "
                        android:textColor="#fff"
                        android:textSize="15dp"
                        android:textStyle="bold" />
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>