android - 如何将一个视图设置在另一个视图之上?
问题描述
我有一个片段。当我单击文本视图时,我会转到另一个片段。但是当第二个片段显示第一个片段的按钮(btn_fragmentAccount_register“)在我的片段上时。在我的第二个片段中是一个显示产品的recyclerview。但是第一个片段的按钮仍然可见。我改变了主题的高度,但没有工作应该做什么我现在做的?
第一个片段 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/white"
android:id="@+id/rel_accountFragment_parent"
android:layout_height="match_parent">
<Button
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
android:textColor="@color/white"
android:layout_below="@id/edt_fragmentAccount_pass"
android:background="@drawable/shape_btn"
android:text="ورود"
android:id="@+id/btn_fragmentAccount_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_fragmentAccount_favorite"
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/view_fragmentAccount_line"
android:text="اگهی های نشان شده"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
第二个片段 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:background="@color/white"
android:id="@+id/rv_favFragment_list"
android:layout_marginTop="8dp"
android:layout_below="@+id/toolbar_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
回收站项目 xml:
<android.support.v7.widget.CardView
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_marginRight="8dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:id="@+id/rel_adsRow_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img_adsRow_icon"
tools:src="@mipmap/ic_launcher"
android:layout_margin="8dp"
android:layout_alignParentLeft="true"
android:layout_width="90dp"
android:layout_height="90dp" />
<TextView
android:textColor="@color/black"
android:maxLines="1"
android:ellipsize="end"
android:id="@+id/txt_adsRow_title"
android:layout_margin="8dp"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/img_adsRow_icon"
tools:text="خودروی سمند"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
android:id="@+id/txt_adsRow_price"
android:layout_below="@id/txt_adsRow_title"
tools:text="1500000 تومان"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
android:layout_below="@id/txt_adsRow_price"
tools:text="لحظاتی پیش"
android:id="@+id/txt_adsRow_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
片段交易kotlin代码:
txtFav.setOnClickListener{
var newContext=context as AppCompatActivity
manager=newContext.supportFragmentManager
var transaction=manager.beginTransaction()
var favFragment=FavFragment()
transaction.add(R.id.rel_accountFragment_parent,favFragment)
transaction.addToBackStack(null)
transaction.commit()
}
解决方案
Fragment fragment = new NameofFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frmFragment, fragment).commit();
<FrameLayout
android:id="@+id/frmFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
推荐阅读
- symfony - Drupal 8 - page.html.twig 不更新网站
- python - Python Z3 求解器未正确报告指数约束的可满足性
- javascript - 从 Python Lambda 中的 POST 请求中提取参数
- javascript - 用于创建测验的 JavaScript 中的异步/等待
- powershell - 使用数组向 ssms 中的用户列表添加权限
- eslint - 为自定义 eslint 规则编写测试时保留 AssertionError 'import'
- python-3.x - 无法在 Seaborn python 中自定义标签和图例
- ruby - 无法安装捆绑程序,显示版本太旧
- pyspark - 使用高性能选择操作重命名 PySpark DataFrame 中的列
- python - 增加一个整数并在循环中写入输出 xml