安卓:按钮滚动视图不可见视图、按钮

2023-09-04 03:04:02 作者:泪、最后一次

我想提出一个Android应用程序输入用户信息,我有两个按键和数字选择器,我的按钮进行自定义,并没有显示在Android的工作室或者preVIEW无论是在模拟器

下面是我的code

 <滚动型
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  的xmlns:工具=htt​​p://schemas.android.com/tool​​s
  工具:上下文=com.app.tarun.dc2.Fragments.AddressFragment>

    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:以下属性来=@扪/ activity_horizo​​ntal_margin
        机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
        机器人:paddingTop =@扪/ activity_vertical_margin
        机器人:paddingBottom会=@扪/ activity_vertical_margin
        机器人:方向=垂直
        >


        <! - 布局按钮 - >
        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:重力=中心
            机器人:方向=横向
            >


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

                <的ImageButton
                    机器人:SRC =@可绘制/ ic_add
                    机器人:ID =@ + ID / medicineEditAddButton
                    机器人:scaleType =fitCenter
                    机器人:填充=20dp
                    机器人:layout_width =match_parent
                    机器人:layout_height =match_parent
                    机器人:背景=@可绘制/ green_button_style/>


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

            < NumberPicker
                机器人:layout_width =0dp
                机器人:ID =@ + ID / medicineEditNumberPicker
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1>

            < / NumberPicker>

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

                <的ImageButton
                    机器人:SRC =@可绘制/ ic_continue
                    机器人:ID =@ + ID / medicineEditContinueButton
                    机器人:scaleType =fitCenter
                    机器人:填充=20dp
                    机器人:layout_width =match_parent
                    机器人:layout_height =match_parent
                    机器人:背景=@可绘制/ yellow_button_style/>


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

        < / LinearLayout中>


<! - 水平线性布局EDITTEXT  - >
<的LinearLayout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向>

    <的EditText
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:提示=名
        机器人:inputType =文本
        机器人:layout_marginTop =25dp/>


    <的EditText
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:提示=姓
        机器人:inputType =文本
        机器人:layout_marginTop =25dp/>


< / LinearLayout中>
<! - 水平线性布局EDITTEXT这里结束(名和姓 - >
< / LinearLayout中>< /滚动型>
 

解决方案 Win10任务视图在哪 怎么打开

一个滚动型是一个的FrameLayout ,这意味着你应该把一个孩子它包含的全部内容,以滚动;这个孩子本身可能是一个布局管理器使用对象的复杂的层次结构。

所以在这里,你必须采取的LinearLayout或RelativeLayout的,然后你必须把不同层次组成的。

 <滚动型机器人:layout_width =match_parent
机器人:layout_height =match_parent
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
工具:上下文=com.app.tarun.dc2.Fragments.AddressFragment>

< LinearLayout中的android:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>

<的LinearLayout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:以下属性来=@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:方向=垂直
    >


    <! - 布局按钮 - >
    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:重力=中心
        机器人:方向=横向
        >


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

            <的ImageButton
                机器人:SRC =@可绘制/ ic_add
                机器人:ID =@ + ID / medicineEditAddButton
                机器人:scaleType =fitCenter
                机器人:填充=20dp
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:背景=@可绘制/ green_button_style/>


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

        < NumberPicker
            机器人:layout_width =0dp
            机器人:ID =@ + ID / medicineEditNumberPicker
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1>

        < / NumberPicker>

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

            <的ImageButton
                机器人:SRC =@可绘制/ ic_continue
                机器人:ID =@ + ID / medicineEditContinueButton
                机器人:scaleType =fitCenter
                机器人:填充=20dp
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:背景=@可绘制/ yellow_button_style/>


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

    < / LinearLayout中>


<! - 水平线性布局EDITTEXT  - >
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向>

   <的EditText
       机器人:layout_width =match_parent
       机器人:layout_height =WRAP_CONTENT
       机器人:layout_weight =1
       机器人:提示=名
       机器人:inputType =文本
       机器人:layout_marginTop =25dp/>


   <的EditText
       机器人:layout_width =match_parent
       机器人:layout_height =WRAP_CONTENT
       机器人:layout_weight =1
       机器人:提示=姓
       机器人:inputType =文本
      机器人:layout_marginTop =25dp/>


< / LinearLayout中>
<! - 水平线性布局EDITTEXT这里结束(名和姓 - >

< / LinearLayout中>

< / LinearLayout中>< /滚动型>
 

希望如此,这code是为你工作。

和你也可以访问此滚动型

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

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>

解决方案

A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents 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 different hierarchy of component.

<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

 
精彩推荐