overlapping a screen in android

2020-05-06 05:01发布

问题:

In the below layout i have a text view named as scanning device.In that am displaying a device name But my device list was displaying above the screen .

can any one please help me how to scroll view should be inside the device list.while scrolling the screen it was displaying the list of the devices but it is displaying above the screen.

want to display inside a screen.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:padding="10dp"
                    android:text="@string/back"
                    android:textAllCaps="true"
                    android:textColor="@color/white"
                    android:visibility="invisible" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:padding="10dp"
                    android:textStyle="bold"
                    android:text="@string/lamp_list"
                    android:textAllCaps="true"
                    android:textColor="@color/white" />

                <TextView
                    android:id="@+id/refresh"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:drawableRight="@drawable/refresh"
                    android:gravity="right"
                    android:padding="10dp"
                    android:textAllCaps="true"
                    android:textColor="@color/white" />

                <ProgressBar
                    android:id="@+id/scanningProgress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="gone" />
            </LinearLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:background="@drawable/baground"
        android:orientation="vertical">

        <TextView
            android:id="@+id/scan_status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="18dp"
            android:gravity="center"
            android:text="@string/start_discovery"
            android:textColor="@color/white"
            android:visibility="gone"
            tools:visibility="visible" />


        <android.support.v7.widget.RecyclerView
            android:id="@+id/deviceListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

In the below layout connect textview was coming out of the layout.

device_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="10dp">


    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:padding="6dp"
        android:src="@drawable/lamp" />

    <TextView
        android:id="@+id/deviceName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left"
        android:textColor="@color/white"
        android:textSize="17sp"
        tools:text="Solar Enviro SSL 2016" />

    <TextView
        android:id="@+id/connect"
        android:layout_width="wrap_content"
        android:layout_height="22dp"
        android:background="@drawable/rounded_red_view"
        android:text="@string/connect"
        android:paddingBottom="1dp"
        android:paddingTop=".2dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:textColor="@color/white"
        android:textSize="17sp" />
</LinearLayout>

回答1:

change this things.. used both wrap_content. i hope you also remove default action bar.

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="?attr/actionBarSize"
        android:orientation="vertical">

    <TextView
            android:id="@+id/scan_status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="18dp"
            android:gravity="center"
            android:visibility="gone"
            tools:visibility="visible" />


    <android.support.v7.widget.RecyclerView
            android:id="@+id/deviceListView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

</LinearLayout>


回答2:

Instead of CoordinatorLayout use linear layout.

if u r a beginner start coding with linear layout. It is easy to understand.

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">