Android: buttons not showing in scrollview

I am making an android application to enter user information because I have two buttons and a compositor, my button is customizable and does not show in either the preview in android studio or in the emulator

Here is my code

<ScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context="com.app.tarun.dc2.Fragments.AddressFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:orientation="vertical"
        >


        <!--Layout for Buttons-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            >


            <com.app.tarun.dc2.CustomViews.SquareLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="25dp"
                android:layout_weight="1">

                <ImageButton
                    android:src="@drawable/ic_add"
                    android:id="@+id/medicineEditAddButton"
                    android:scaleType="fitCenter"
                    android:padding="20dp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/green_button_style"/>


            </com.app.tarun.dc2.CustomViews.SquareLayout>

            <NumberPicker
                android:layout_width="0dp"
                android:id="@+id/medicineEditNumberPicker"
                android:layout_height="wrap_content"
                android:layout_weight="1">

            </NumberPicker>

            <com.app.tarun.dc2.CustomViews.SquareLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_margin="25dp"
                android:layout_weight="1">

                <ImageButton
                    android:src="@drawable/ic_continue"
                    android:id="@+id/medicineEditContinueButton"
                    android:scaleType="fitCenter"
                    android:padding="20dp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/yellow_button_style"/>


            </com.app.tarun.dc2.CustomViews.SquareLayout>

        </LinearLayout>


<!--Horizontal Linear Layout for EDITTEXT-->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="First Name"
        android:inputType="text"
        android:layout_marginTop="25dp"/>


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="Last Name"
        android:inputType="text"
        android:layout_marginTop="25dp"/>


</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT end here(First name and last name-->
</LinearLayout></ScrollView>

      

0


source to share


4 answers


Try enabling scroll view in the layout. This is how I achieved it for my project:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.com.atr.LoginActivity" >

    <ScrollView
         android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:id="@+id/txthello"></TextView>

    <EditText
        android:id="@+id/txtApp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txthello"
        android:layout_marginTop="18dp"
        android:hint="Enter Application Code"/>

      <EditText
        android:id="@+id/txtModuleId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtApp"
        android:layout_marginTop="18dp"
        android:hint="Enter Module Id"/>

         <EditText
        android:id="@+id/txtModuleCode"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtModuleId"
        android:layout_marginTop="18dp"
        android:hint="Enter Module Code"/>

           <EditText
        android:id="@+id/txtModuleType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtModuleCode"
        android:layout_marginTop="18dp"
        android:hint="Enter Module Type"/>
          <EditText
        android:id="@+id/txtSubModuleId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtModuleType"
        android:layout_marginTop="18dp"
        android:hint="Enter Sub Module Id"/>

      <EditText
        android:id="@+id/txtSubModuleCode"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtSubModuleId"
        android:layout_marginTop="18dp"
        android:hint="Enter Sub Module Code"/>

       <EditText
        android:id="@+id/txtUserId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtSubModuleCode"
        android:layout_marginTop="18dp"
        android:hint="Enter User Id"/>

         <EditText
        android:id="@+id/txtDateFrom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtUserId"
        android:layout_marginTop="18dp"
        android:hint="From Date (mmm-dd-yyyy)"/>

           <EditText
        android:id="@+id/txtDateTo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/txtDateFrom"
        android:layout_marginTop="18dp"
        android:hint="To Date (mmm-dd-yyyy)"/>

            <Button
        android:id="@+id/btnCallService"
        android:layout_width="80dp"
        android:layout_height="45dp"

        android:layout_below="@+id/txtDateTo"
        android:layout_toRightOf="@+id/txtDateTo"
        android:layout_marginTop="18dp"

        android:layout_alignParentLeft="true"
        android:text="Send"/>
  </RelativeLayout>
    </ScrollView>
</RelativeLayout>

      



Just to give you a basic idea :)

0


source


Change your own layout width from 0dp to wrap content / match_parent depending on your needs. I think this might solve your problem. I have an edited layout at the bottom.



<com.app.tarun.dc2.CustomViews.SquareLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="25dp"
            android:layout_weight="1">

            <ImageButton
                android:src="@drawable/ic_add"
                android:id="@+id/medicineEditAddButton"
                android:scaleType="fitCenter"
                android:padding="20dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/green_button_style"/>


        </com.app.tarun.dc2.CustomViews.SquareLayout>

        <NumberPicker
            android:layout_width="wrap_content"
            android:id="@+id/medicineEditNumberPicker"
            android:layout_height="wrap_content"
            android:layout_weight="1">

        </NumberPicker>

        <com.app.tarun.dc2.CustomViews.SquareLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="25dp"
            android:layout_weight="1">

            <ImageButton
                android:src="@drawable/ic_continue"
                android:id="@+id/medicineEditContinueButton"
                android:scaleType="fitCenter"
                android:padding="20dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/yellow_button_style"/>


        </com.app.tarun.dc2.CustomViews.SquareLayout>

      

0


source


Add android: weightSum = "[any int]" to your first LinearLayout

0


source


ScrollView is FrameLayout

, which means you should place one child

, containing all the content to scroll; this child may itself be a layout manager with a complex hierarchy of objects.

So here you have to take LinearLayout or RelativeLayout and then you have to put another component hierarchy.

<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.tarun.dc2.Fragments.AddressFragment">

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    >


    <!--Layout for Buttons-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        >


        <com.app.tarun.dc2.CustomViews.SquareLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="25dp"
            android:layout_weight="1">

            <ImageButton
                android:src="@drawable/ic_add"
                android:id="@+id/medicineEditAddButton"
                android:scaleType="fitCenter"
                android:padding="20dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/green_button_style"/>


        </com.app.tarun.dc2.CustomViews.SquareLayout>

        <NumberPicker
            android:layout_width="0dp"
            android:id="@+id/medicineEditNumberPicker"
            android:layout_height="wrap_content"
            android:layout_weight="1">

        </NumberPicker>

        <com.app.tarun.dc2.CustomViews.SquareLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="25dp"
            android:layout_weight="1">

            <ImageButton
                android:src="@drawable/ic_continue"
                android:id="@+id/medicineEditContinueButton"
                android:scaleType="fitCenter"
                android:padding="20dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/yellow_button_style"/>


        </com.app.tarun.dc2.CustomViews.SquareLayout>

    </LinearLayout>


<!--Horizontal Linear Layout for EDITTEXT-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

   <EditText
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_weight="1"
       android:hint="First Name"
       android:inputType="text"
       android:layout_marginTop="25dp"/>


   <EditText
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_weight="1"
       android:hint="Last Name"
       android:inputType="text"
      android:layout_marginTop="25dp"/>


</LinearLayout>
<!--Horizontal Linear Layout for EDITTEXT end here(First name and last name-->

</LinearLayout>

</LinearLayout></ScrollView>

      

Hope this code works for you.

And you can also visit this ScrollView

0


source







All Articles