ScrollView Start from Top (SSFT)


SSFT:   SOLD       




Hi dev, this problem is my new experience while working on the Android App project. What is that strange thing? So here it is, in the end I have to deal with different dimensions. It started when my boss asked that the application I was developing be able to adapt to the Android 6.0 Marshmallow population (API 23) where, on average, devices with this OS are under 5.8 inches in size, which means that my activity content must be responsive to that dimension, so I have to make it scrollable, an example of a case study at that time was for a form with quite a lot of fields, but no problem if it was in the 5.9 inch or 6 inch dimension, the content was fixed or passed that dimension, no need to scroll.

Okay, all the reviews above are actually not a problem, the problem is, when I implement the ScrollView component, my form page actually appears half, in Javanese terms the content is " MLOTROK ", so  the scroll does not start from the top  (by default why is it scrolling 20%), or in other words the topmost content does not appear for the first time, so the user has to scroll up first before they can start filling out the form at the very top. I think this will ruin the UX of my app, even though the UI is good, but if the behavior is like this it will be bad for the user.

I have tried various methods such as  mainScrollView.pageScroll(View.FOCUS_UP),  scrollTo(0,0),  scrollDirection(View.FOCUS_UP), and many other relevant methods that I have applied, but all of them did not produce results.

But in the end my google fu tricks paid off, and here is the solution.

//solved make scroll view beginning at top
scroll_home.fullScroll(ScrollView.FOCUS_UP)
scroll_home.smoothScrollTo(0,0)

Done!

Fix ScrollView Cannot Start From Top

Hello guys, this time I want to share my experience while playing around with Android scrollview, where when I switch from one activity to another. Strangely when I enter an activity that has a scrollview, the first focus that is displayed is the content in the middle.. so in Javanese it's a bit mlotrok... like wearing pants is mlotrok.. kwkwwk njirr, every time the user opens this activity, the user has to scroll up first, it seems like the UX is really bad, right?

Okay, long story short as usual, I did the trick  google fu and found the solution. Okay, let's highlight the code in the activity that I mean above, for example like this.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollViewLuogo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:adjustViewBounds="true"
            android:maxHeight="200dp"
            android:maxWidth="200dp"
            android:scaleType="fitXY"
            android:src="@android:drawable/ic_menu_gallery" />

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/nomeTVActivityLuogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:textSize="17sp"
                android:textColor="#005788" />

            <TextView
                android:id="@+id/indirizzoTVActivityLuogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout2"
        android:layout_marginTop="10dp"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageViewMappaLuogo"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="14dp"
            android:layout_marginTop="5dp"
            android:scaleType="fitXY"
            android:src="@drawable/sfondo_mappa" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="14dp"
            android:text="Immagini"
            android:textColor="#97d6f9" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:layout_marginLeft="14dp"
            android:layout_marginRight="14dp"
            android:layout_marginTop="5dp"
            android:background="#97d6f9" />

        <com.example.mappine.ExpandableHeightGridView
            android:id="@+id/gridViewLuogo"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:numColumns="3" >
        </com.example.mappine.ExpandableHeightGridView>

    </LinearLayout>

</RelativeLayout>

I have tried using several functions that I think are very relevant for solving my problem, such as  scrollView.fullScroll(ScrollView.FOCUS_UP) but the results are zero, I also tried this method  scrollView.scrollTo(0, 0) but the results are still the same.

The Solution

Basically, the problem lies in the child GridView / ListView which will automatically request focus to its parent, which occurs when the entire layout is completed rendered, so handling this behavior is very ineffective if done programmatically, so the most effective, concise and clear way is to disable focus.

listView.setFocusable(false)

Post a Comment

Previous Next

نموذج الاتصال