如何在父布局之前包含布局属性? [英] How do I include layout attribute before parent layout?

查看:106
本文介绍了如何在父布局之前包含布局属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个活动",而其他则是片段.我的父布局是cardview,我想使用include布局标签在顶部添加另一个布局.在下面,我发布了输出图像和代码:.

I am using One Activity and others are fragments. My parent layout is cardview and I want to add another layout at the top the using include layout tag. Below I posted output images and code:.

这是我的卡布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:cardBackgroundColor="@android:color/transparent"
android:elevation="0dp">
<include layout="@layout/edit_text"/>
<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="25sp"
    android:paddingLeft="10dp"
    android:textColor="#4928ef"
    android:textStyle="italic"/>
</android.support.v7.widget.CardView>

这是我的常用布局,我必须将其包括在上述卡片布局中

And this is my common layout, which I have to include in above card layout

edit_text.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="GO"
    android:id="@+id/go"
    android:layout_alignParentRight="true"
    />
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Quick Search"
    android:layout_alignParentLeft="true"/>
</RelativeLayout>

输出

单击此处以显示以上代码的输出

我试图将cardview的父级更改为LinearLayout,并将cardview的子级更改为子级,但是我不知道为什么第一个仅显示的列表项(文本视图)被忽略而其他项则被忽略.我正在尝试进行如下布局:

I tried to change cardview parent to LinearLayout and cardview as child but I don't know why list item (textview) the first one only displays and others are ignored. I am trying to make layout like below:

单击此处查看我的期望

推荐答案

删除

<include layout="@layout/edit_text"/>

从cardView布局中选择,因为cardView应该只有一个ChildView.
据我了解,您想在顶部使用搜索栏.
所以这是我的实现:

from your cardView layout, because cardView should have only one ChildView.
so as i understand, you want to use search bar on top.
so here is my implementation:

<?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="match_parent"
    android:orientation="vertical"
    tools:context="com.tiikr.OverlayActivity">

    <include layout="@layout/edit_text"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scrollbars="vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin">

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

</LinearLayout>

所以在这里我将LinearLayout用作视图的父级,顶部是您的搜索栏布局,下面是您需要在代码中使用cardview布局填充的listView

so here i use LinearLayout as a parent of the view, and on top is your search bar layout, and down is the listView wich you need to populate in the code with your cardview layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:cardBackgroundColor="@android:color/transparent"
android:elevation="0dp">
<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="25sp"
    android:paddingLeft="10dp"
    android:textColor="#4928ef"
    android:textStyle="italic"/>
</android.support.v7.widget.CardView>

通过RecyclerView参见上面的代码

这篇关于如何在父布局之前包含布局属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆