简体   繁体   English

SearchBar 和 RecyclerView 和 CardView 的问题

[英]Issue with SearchBar and RecyclerView and CardView

I'm using the SearchBar following the tutorial Android Development Tutorial - Search on SQLite data .我正在按照教程Android Development Tutorial - Search on SQLite data使用SearchBar I have a problem with the layout.我的布局有问题。 Please see attached image.请参阅附图。 I'm using CardView and RecyclerView .我正在使用CardViewRecyclerView Can you please tell me what is wrong in my layout?你能告诉我我的布局有什么问题吗?

check image检查图像

在此处输入图片说明

main_activity.xml main_activity.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.mancj.materialsearchbar.MaterialSearchBar
        android:id="@+id/search_bar"
        android:layout_alignParentTop="true"
        app:mt_speechMode="false"
        app:mt_hint="Search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

    </android.support.v7.widget.RecyclerView>

</RelativeLayout>

layout_item.xml layout_item.xml

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cardElevation="0dp"
    android:layout_margin="9dp">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_margin="8dp"
        android:background="@android:color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:src="@drawable/ic_account_circle_black_24dp"
            android:layout_width="70dp"
            android:layout_height="70dp" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_weight="9"
            android:layout_width="0dp"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/name"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textAllCaps="true"
                android:textStyle="bold"
                android:text="Eddy Lee"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/email"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textStyle="italic"
                android:text="eddylee@aol.com"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/phone"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textAllCaps="true"
                android:textStyle="bold"
                android:text="(222)888-888"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/address"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textAllCaps="true"
                android:textStyle="normal"
                android:text="new york"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            </TextView>


        </LinearLayout>
    </LinearLayout>

Thank you for attention感谢您的关注

Change your layout_item.xml CardView height="wrap_content"更改您的layout_item.xml CardView height="wrap_content"

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="0dp"
    android:layout_margin="9dp">

    ...........................

</android.support.v7.widget.CardView>

update your view and take parent height wrap_content更新您的视图并采用父高度 wrap_content

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="0dp"
    android:layout_margin="9dp">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_margin="8dp"
        android:background="@android:color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:src="@drawable/ic_account_circle_black_24dp"
            android:layout_width="70dp"
            android:layout_height="70dp" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_weight="9"
            android:layout_width="0dp"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/name"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textAllCaps="true"
                android:textStyle="bold"
                android:text="Eddy Lee"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/email"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textStyle="italic"
                android:text="eddylee@aol.com"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/phone"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textAllCaps="true"
                android:textStyle="bold"
                android:text="(222)888-888"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/address"
                android:layout_marginLeft="10dp"
                android:gravity="center_vertical|start"
                android:textAllCaps="true"
                android:textStyle="normal"
                android:text="new york"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            </TextView>


        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

Use wrap_content for cardView in layout_item在 layout_item 中为 cardView 使用 wrap_content

<android.support.v7.widget.CardView
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:layout_width="match_parent"
   android:layout_height="wrap_content "
   app:cardElevation="0dp"
   android:layout_margin="9dp">

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

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