gpt4 book ai didi

java - 将 ScrollView 添加到整个 Activity

转载 作者:行者123 更新时间:2023-12-02 11:00:24 25 4
gpt4 key购买 nike

我想将 ScrollView 添加到我的整个 Activity 中。我对每个布局和 View 都给予了重视,因为我希望我的屏幕是通用的。但是通过在我的 Activity 顶部添加 ScrollView ,它会破坏我的整个屏幕,我无法看到所有的文本,并在每件事之间添加了额外的空格。我希望我已经清楚地说明了我的问题,这真的让我很恼火,因为我对每个布局和 View 都给予了重视,而不是为什么它改变了我的屏幕 View 。我也看到这里已经发布了相同问题的解决方案,但我对此不满意。我想要的只是在不影响布局和文本的情况下滚动整个 Activity 的简单方法。以下是添加 ScrollView 后我的 Activity 的图像:

[ 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>

最佳答案

从布局中删除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>

关于java - 将 ScrollView 添加到整个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51378528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com