I have a layout file of a fragment in which i am trying to implement scrollview in it. I have made Scrollview as a parent view but still it doesn't scoll up and down. Below is the code of my layout file .
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lime_green">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Spinner
android:id="@+id/spinnerLanguage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true" />
<androidx.cardview.widget.CardView
android:id="@+id/cardViewAvatar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/imageAvatar"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_marginTop="20dp"
android:src="@drawable/avatar" />
<TextView
android:id="@+id/textAvatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="40dp"
android:text="@string/select_your_avatar"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/blue_card" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardViewAvatar"
android:background="@color/white"
android:layout_marginTop="40dp"
android:id="@+id/cardviewNotify">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/notification"
android:id="@+id/imageNotify" />
<TextView
android:id="@+id/textNotify"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:textColor="@color/blue_card"
android:layout_gravity="center"
android:text="@string/notifications" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardviewNotify"
android:background="@color/white"
android:id="@+id/cardviewProgress">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/progresstrack"
android:id="@+id/imageProgress" />
<TextView
android:id="@+id/textProgress"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:textColor="@color/blue_card"
android:text="@string/progress_track" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardviewProgress"
android:background="@color/white"
android:id="@+id/cardviewShare">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/sharelinks1"
android:id="@+id/imageShare" />
<TextView
android:id="@+id/textshare"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:textColor="@color/blue_card"
android:text="Share" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardviewShare"
android:background="@color/white"
android:id="@+id/cardviewSupport">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/support1"
android:id="@+id/imageSupport" />
<TextView
android:id="@+id/textSupport"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:textColor="@color/blue_card"
android:text="Help Desk" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardviewSupport"
android:background="@color/white"
android:id="@+id/cardviewFeature">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/featurerequest"
android:id="@+id/imageFeature" />
<TextView
android:id="@+id/textFeature"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:textColor="@color/blue_card"
android:text="@string/feature_request" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardviewFeature"
android:background="@color/white"
android:id="@+id/cardviewAbout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/aboutapp"
android:id="@+id/imageAbout" />
<TextView
android:id="@+id/textAboutApp"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:textColor="@color/blue_card"
android:text="About" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cardviewAbout"
android:layout_marginTop="50dp"
android:background="@color/white"
android:id="@+id/cardviewDelete">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:src="@drawable/deletedata"
android:id="@+id/imageDelete" />
<TextView
android:id="@+id/textDeleteData"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:textColor="@color/blue_card"
android:text="Delete Data" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</ScrollView>
Below is the fragment code
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.visuallithuanian.R
import com.example.visuallithuanian.adapter.SpinnerAdapter
import com.example.visuallithuanian.databinding.FragmentSettingsBinding
import com.example.visuallithuanian.ui.activities.FirstScreen
import com.google.android.material.bottomnavigation.BottomNavigationView
class SettingsFragment : Fragment() {
private lateinit var binding:FragmentSettingsBinding
lateinit var bottomNav: BottomNavigationView
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentSettingsBinding.inflate(layoutInflater,container,false)
// Taking the BottomNavigation view instance from Activity into Fragment
bottomNav = (activity as? FirstScreen)?.findViewById(R.id.bottomNavigationView)!!
bottomNav.visibility = View.VISIBLE
return binding.root
}
}
I am trying to implement Scrolling feature on my screen but my screen is not getting scrolling. I have made Scrollview as my parent view but still not success.
The height of the inner interface must exceed the height of the screen at that time. then the scrollview will work. Try opening the app on a smaller screen