无论我如何添加约束,包含RecyclerView的片段都不会发生任何变化。
我添加了一个工具栏:
在MainActivity中创建
覆盖fun oncreate(savedinstancestate:bundle?){
super.oncreate(保存到状态)
setContentView(r.layout.activity_main)//要查找不一致项,请执行以下操作
val demo=demodatabuilder()。
//将工具栏设置为支持操作栏
设置支持操作栏(工具栏)
//现在获取支持操作栏
val actionbar=支持actionbar
//设置工具栏标题/应用标题
行动吧!!.title=“敬畏”
//设置操作栏/工具栏子标题
actionBar.subtitle=“应用程序副标题”
//设置操作栏高度
actionbar.elevation=4.0f
toolbar.setnavigationicon(R.drawable.ic_arrow_back_black_24dp)
toolbar.setNavigationonClickListener->onBackpressed()
StartCategoryHome(保存到状态)
}
< /代码>
活动\main.xml
<?xml version=“1.0”encoding=“utf-8”?gt;
<android.support.constraint.constraintlayout(限制布局)
xmlns:android=“http:
xmlns:app=“http:
xmlns:tools=“http:
android:layout_width=“匹配父级”
android:layout_height=“匹配父级”
android:id=“@+id/root_layout”>
<android.support.v7.widget.toolbar
android:id=“@+id/工具栏”
android:layout_width=“匹配父级”
android:layout_height=“0dp”
android:background=“?属性/颜色主要“
安卓:minheight=“57dp”
安卓:padding=“1dp”
app:layout_constraintop_totopof=“父级”
app:subtitletextcolor=“f5fbff”
app:titletextcolor=“fff”/>
片段
android:id=“@+id/categoylist\u片段”
android:name=“za.co.aweza.awezamediphrases.fragments.categorylistfragment”
android:layout_width=“匹配父级”
android:layout_height=“包装内容”
android:layout_margintop=“112dp”
app:layout_constraintop_tobottomof=“@+id/工具栏”
工具:layout=“@layout/fragment_hcp_category”/>gt;
</android.support.constraint.constraintlayout>
< /代码>
您会注意到,在上面的布局代码中,我有一个非常牵强的约束,我试图使用它。
以下是它在设计视图中的显示方式:

但是不管我做什么尝试,片段中RV的第一个单元大部分位于工具栏下面。我错过了什么?在主要活动中
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val demo = DemoDataBuilder()
setSupportActionBar(toolbar)
val actionBar = supportActionBar
actionBar!!.title = "AwezaMed"
actionBar.subtitle = "App subtitle"
actionBar.elevation = 4.0F
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp)
toolbar.setNavigationOnClickListener { _ -> onBackPressed()}
startCategoryHome(savedInstanceState)
}
活动\main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:id="@+id/root_layout">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/colorPrimary"
android:minHeight="57dp"
android:padding="1dp"
app:layout_constraintTop_toTopOf="parent"
app:subtitleTextColor="#f5fbff"
app:titleTextColor="#fff" />
<fragment
android:id="@+id/categoyList_fragment"
android:name="za.co.aweza.awezamediphrases.fragments.CategoryListFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="112dp"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
tools:layout="@layout/fragment_hcp_category" />
</android.support.constraint.ConstraintLayout>
您会注意到在上面的布局代码中,我尝试使用了一个非常牵强的约束。
以下是它在设计视图中的显示方式:

但是不管我做什么尝试,片段中RV的第一个单元大部分位于工具栏下面。我错过了什么?