简体   繁体   English

Android:滚动视图中不可见的按钮

[英]Android : buttons not visible in scrollview

I am making an android app to enter user information, for that I have two button and number picker, my button are customize and are not showing in either preview in android studio neither in emulator 我正在制作一个Android应用程序来输入用户信息,因为我有两个按钮和数字选择器,我的按钮是自定义的,并没有显示在Android工作室的预览中既不在模拟器中

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>

Try including your scroll view in a layout. 尝试在布局中包含滚动视图。 Here is how i have achieved it for a project of mine: 以下是我为我的项目实现的方法:

<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 :) 只是为了给你一个基本的想法:)

Change your custom layout's width from 0dp to wrap content/match_parent depending on your need. 根据需要将自定义布局的宽度从0dp更改为包装内容/ match_parent I think that may solve your problem. 我认为这可以解决你的问题。 I have your edited layout in below. 我在下面编辑了你的编辑。

<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>

在你的第一个LinearLayout上添加一个android:weightSum =“[any int]”

A ScrollView is a FrameLayout , meaning you should place one child in it containing the entire contents to scroll; ScrollView是一个FrameLayout ,意味着you should place one child包含整个内容的子项进行滚动; 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 different hierarchy of component. 所以在这里你必须采用LinearLayout或RelativeLayout然后你必须放置不同的组件层次结构。

<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 so this code is work for you. 希望这段代码对你有用。

And you can also visit this ScrollView 您还可以访问此ScrollView

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

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