简体   繁体   English

ScrollView 不作为父级滚动,RelativeLayout 作为子级滚动

[英]ScrollView not scrolling as parent and RelativeLayout as child

I know this question has been asked several times before, but none of the answers worked for me so I am reposting it again.我知道这个问题之前已经被问过好几次了,但是没有一个答案对我有用,所以我再次重新发布它。 I am using a scrollview as a parent layout and a relative layout as child.我使用滚动视图作为父布局,使用相对布局作为子布局。 Here is my code:这是我的代码:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:background="@drawable/grdnt">
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"    >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:paddingLeft="60dp"
            android:paddingRight="60dp">
            <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="horizontal"
                    android:padding="16dp">
                    <ImageView
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:src="@drawable/ic_ip"
                        android:layout_gravity="center"/>
                    <EditText
                        android:id="@+id/ip"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Server Adress"
                        android:textColorHint="#d9e5f3"
                        android:layout_marginLeft="15dp"
                        android:background="#00000000"
                        android:letterSpacing="0.1"
                        android:textSize="16dp"
                        android:inputType="text"
                        android:textColor="#fff"
                        android:fontFamily="@font/lato"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#4a5a71"></LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:padding="16dp">
    
                    <ImageView
                        android:layout_width="18dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:src="@drawable/ic_g" />
                    <EditText
                        android:id="@+id/port"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Port"
                        android:textColorHint="#d9e5f3"
                        android:layout_marginLeft="15dp"
                        android:background="#00000000"
                        android:inputType="text"
                        android:letterSpacing="0.1"
                        android:textSize="16dp"
                        android:textColor="#fff"
                        />
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#4a5a71"></LinearLayout>
    
            </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="60dp"
            android:paddingRight="60dp"
            android:orientation="vertical"
            android:gravity="bottom"
            android:layout_marginBottom="20dp">
            <TextView
                android:id="@+id/sub"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#009a9a"
                android:text="Submit"
                android:textColor="#d9e5f3"
                android:textStyle="bold"
                android:gravity="center"
                android:layout_gravity="bottom"
                android:padding="16dp"
                android:layout_marginBottom="50dp"
                android:letterSpacing="0.2"/>
    
    
        </LinearLayout>
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_marginBottom="400dp">
        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:src="@drawable/ic_settings"
            />
    </LinearLayout>
</RelativeLayout>
</ScrollView>

I tried to put it inside LinearLayout but still nothing, I also tried to change the RelativeLayout to LinearLayout and nothing.我试图将它放在 LinearLayout 中但仍然没有,我还尝试将 RelativeLayout 更改为 LinearLayout 并且什么也没有。

Any suggestions?有什么建议么?

use this one用这个

   <?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:background="@drawable/user">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_marginBottom="20dp">
                <ImageView
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:src="@drawable/images"
                    />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:paddingLeft="60dp"
                android:paddingRight="60dp"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="20dp">

                <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="horizontal"
                        android:padding="16dp">
                        <ImageView
                            android:layout_width="20dp"
                            android:layout_height="20dp"
                            android:src="@drawable/images"
                            android:layout_gravity="center"/>
                        <EditText
                            android:id="@+id/ip"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="Server Adress"
                            android:textColorHint="#d9e5f3"
                            android:layout_marginLeft="15dp"
                            android:background="#00000000"
                            android:letterSpacing="0.1"
                            android:textSize="16dp"
                            android:inputType="text"
                            android:textColor="#fff"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#4a5a71"></LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="16dp">

                        <ImageView
                            android:layout_width="18dp"
                            android:layout_height="20dp"
                            android:layout_gravity="center"
                            android:src="@drawable/images" />
                        <EditText
                            android:id="@+id/port"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:hint="Port"
                            android:textColorHint="#d9e5f3"
                            android:layout_marginLeft="15dp"
                            android:background="#00000000"
                            android:inputType="text"
                            android:letterSpacing="0.1"
                            android:textSize="16dp"
                            android:textColor="#fff"
                            />
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#4a5a71"></LinearLayout>

                </LinearLayout>
            </LinearLayout>
            
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="60dp"
                android:paddingRight="60dp"
                android:orientation="vertical"
                android:gravity="bottom"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="400dp">

                <TextView
                    android:id="@+id/sub"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#009a9a"
                    android:text="Submit"
                    android:textColor="#d9e5f3"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:layout_gravity="bottom"
                    android:padding="16dp"
                    android:layout_marginBottom="50dp"
                    android:letterSpacing="0.2"/>


            </LinearLayout>


        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</LinearLayout>

Ok, i figured out what was the problem and I hope this might help someone one day.好的,我想出了问题所在,我希望有一天这对某人有所帮助。 The problem was my style.xml file i was using the item "windowFullscreen" wich it was preventing the app from scrolling.问题是我的风格。xml 文件我使用的是“windowFullscreen”项目,它阻止了应用程序滚动。

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- Customize your theme here. -->
    ...
    <item name="android:windowFullscreen">true</item>
</style>

So all i've had to do was deleting that full screen attribute.所以我所要做的就是删除那个全屏属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM