SearchBar和RecyclerView和CardView的问题

时间:2018-09-25 08:17:45

标签: java android layout android-recyclerview android-cardview

我正在使用Android Development Tutorial - Search on SQLite data教程之后的SearchBar。我的布局有问题。请参阅所附图片。我正在使用CardViewRecyclerView。您能告诉我我的布局有什么问题吗?

查看图片

enter image description here

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

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

感谢您的关注

3 个答案:

答案 0 :(得分:2)

更改您的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>

答案 1 :(得分:1)

更新您的视图并获取父项的高度wrap_content

library(dplyr)
library(tidyr)

DF1 <- data.frame("SRNo." = 1:5, Value = c("1ABCD2EFGH3IJKL","1ABCD2EFGH3IJKL/7MLPO0OKMN8MNBV","3ABCD4EFGH5IJKL","3ABCD4EFGH5IJKL/1ABCD2EFGH3IJKL","7MLPO0OKMN8MNBV/9IUYT7HGFD3LKJH"), stringsAsFactors = F) %>% tbl_df()

DF2 <- data.frame("SRNo." = 1:7, Value = c("1ABCD2EFGH3IJKL","3ABCD4EFGH5IJKL","6PQRS7TUVW8XYZA","5FGHI9XUZX1RATP","9AGTY6UGFW0AAUU","6TEYD7RARA8MHAT","9IUYT7HGFD3LKJH"), stringsAsFactors = F) %>%tbl_df()

DF1 %>%
  separate(Value, c("Value1", "Value2"), sep = "/")  %>%
  mutate(dat = case_when(
    Value1 %in% DF2$Value ~ Value1,
    Value2 %in% DF2$Value ~ Value2,
    TRUE ~ NA_character_
  ))

# # A tibble: 5 x 4
#   SRNo. Value1          Value2          dat            
#   <int> <chr>           <chr>           <chr>          
# 1     1 1ABCD2EFGH3IJKL NA              1ABCD2EFGH3IJKL
# 2     2 1ABCD2EFGH3IJKL 7MLPO0OKMN8MNBV 1ABCD2EFGH3IJKL
# 3     3 3ABCD4EFGH5IJKL NA              3ABCD4EFGH5IJKL
# 4     4 3ABCD4EFGH5IJKL 1ABCD2EFGH3IJKL 3ABCD4EFGH5IJKL
# 5     5 7MLPO0OKMN8MNBV 9IUYT7HGFD3LKJH 9IUYT7HGFD3LKJH

答案 2 :(得分:1)

在layout_item中将wrap_content用于cardView

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