Falmesino
Falmesino

Reputation: 135

How to make the layout scrollable?

enter image description here

That's edit form in My application, there's one button left after "Simpan Perubahan" button. How to make my form scrollable and make the last button visible and clickable?

I do not know much about layouts.

code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
      <TextView
        android:text="ID Objek"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <EditText
        android:id="@+id/tv_obj_id"
        android:editable="false"
        android:singleLine="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <TextView
        android:text="Nama Objek"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <EditText
        android:id="@+id/tv_obj_nama"
        android:editable="true"
        android:singleLine="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <TextView
        android:text="Detail Objek"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <EditText
        android:id="@+id/tv_obj_det"
        android:editable="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <TextView
        android:text="Koordinat Objek"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <TextView
        android:text="Longitude"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <EditText
        android:id="@+id/tv_obj_long"
        android:editable="true"
        android:singleLine="true"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <TextView
        android:text="Latitude"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <EditText
        android:id="@+id/tv_obj_lat"
        android:editable="true"
        android:singleLine="true"
        android:inputType="numberDecimal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <Button 
        android:id="@+id/btn_obj_submit"
        android:text="Simpan Perubahan"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
      <Button 
        android:id="@+id/btn_obj_back"
        android:text="Simpan Perubahan"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

What should i do to my xml file?

Upvotes: 1

Views: 1510

Answers (3)

Mohit kumar
Mohit kumar

Reputation: 126

You can make List.builder or listview or use scrollable layout using scroll widget in flutter. below is a code you can customized according to your need i did it with List.builder

List litems = ["1","2","3","4"];

return Scaffold(
  backgroundColor: Colors.grey[200],
  body: Padding(
    padding: const EdgeInsets.all(18.0),
    child: Column(
      children: [
        Padding(
          padding: const EdgeInsets.fromLTRB(10.0, 0.0, 0.0, 18.0),
          child: Align(
            alignment: Alignment.topLeft,
            child: ListTile(
              leading: Row(
                children: [
                  Text(
                    "LeaderBoard",
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                        fontSize: 30),
                  ),
                  Icon(
                    Icons.trending_up,
                    size: 30,
                  ),
                ],
              ),
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(20.0),
          child: Row(
            children: [
              Expanded(
                child: Align(
                    alignment: Alignment.topLeft,
                    child: Text(
                      "Person",
                    )),
              ),
              Align(
                  alignment: Alignment.topRight,
                  child: Text(
                    "Score",
                  )),
            ],
          ),
        ),
        Expanded(
          child: new ListView.builder(
              itemCount: litems.length,
              itemBuilder: (BuildContext context, int index) {
                return new Card(
                  color: Colors.white,
                  child: ListTile(
                    leading: Text(litems[index]),
                    title: Text(litems[index]),
                  ),
                );
              }),
        ),
      ],
    ),
  ),
);

} }

Upvotes: 0

denis.solonenko
denis.solonenko

Reputation: 11765

Your layout should look like

<LinearLayout vertical>
    <ScrollView>
        <LinearLayout vertical>
        ... here are your fields ...
        </LinearLayout>
    </ScrollView>
    <LinearLayout horizontal>
    ... here are your buttons ...
    </LinearLayout>
</LinearLayout>

Upvotes: 2

Plamen Nikolov
Plamen Nikolov

Reputation: 4187

Use ScrollView component in the xml. example

Upvotes: 1

Related Questions