我正在阅读关于Android的房间库.我看到他们改变包装android来androidx.我不明白.请有人解释一下.
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
即使这也适用于android包装.
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
Run Code Online (Sandbox Code Playgroud)
androidx而不是android.android android-architecture-components android-jetpack androidx
如何从XML 设置RecyclerView layoutManager?
<android.support.v7.widget.RecyclerView
app:layoutManager="???"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud) 我发现了如何使用预览列表项
tools:listitem="@layout/my_item_layout"
Run Code Online (Sandbox Code Playgroud)
但android studio正在将recyclerview预览为垂直列表.有没有办法告诉Android Studio我会附加一个水平,LinearLayoutManager以便它可以预览水平列表?
当我将RecyclerView添加到布局时,它以垂直顺序显示为列表视图.我正在使用tools:listitem这个.有没有办法,它在Android Studio编辑器中显示为网格而不是列表?
我知道你设置的时候
tools:text="Sample text"
Run Code Online (Sandbox Code Playgroud)
在a中TextView,您将在Android Studio的预览模式下看到示例文本,但不会在实际应用中看到.我想为a中的项目做这个RecyclerView,但我似乎无法做到.这是我到目前为止所做的:
在RecyclerView(名为content_feed)中:
tools:listitem="@layout/cell_feed"
Run Code Online (Sandbox Code Playgroud)
在单元格中(名称为cell_feed):
tools:showIn="@layout/content_feed"
Run Code Online (Sandbox Code Playgroud)

这是xml文件:
cell_feed.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/height_feed_cell"
android:layout_marginLeft="@dimen/margin_feed_cell"
android:layout_marginRight="@dimen/margin_feed_cell"
android:orientation="horizontal"
tools:showIn="@layout/content_feed">
<LinearLayout
android:id="@+id/timeLayouts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/alpha_feed_secondary_text"
android:textSize="@dimen/size_feed_secondary_text"
android:id="@+id/startTimeText"
tools:text="8:00 AM"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/alpha_feed_secondary_text"
android:textSize="@dimen/size_feed_secondary_text"
android:id="@+id/endTimeText"
tools:text="10:00 AM"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_feed_cell_text"
android:layout_toRightOf="@+id/timeLayouts"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_bottom_feed_cell_title"
android:textSize="@dimen/size_feed_cell_title"
android:textStyle="bold"
android:id="@+id/titleText"
tools:text="Event title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/alpha_feed_secondary_text"
android:textSize="@dimen/size_feed_secondary_text"
android:id="@+id/captionText"
tools:text="Event caption"/>
</LinearLayout>
<CheckBox
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) android android-studio android-recyclerview android-tools-namespace android-layout-editor
RecyclerView以垂直方向显示,并且无法设置此属性,因为方向属于LinearLayoutManager对象.有什么方法可以模拟HORIZONTAL布局?
无论如何,linearLayoutManager在代码中创建的设置为HORIZONTAL.
llm.setOrientation(LinearLayoutManager.HORIZONTAL);
Run Code Online (Sandbox Code Playgroud)
我尝试用来tools:listitem在上显示样式正确的样本数据RecyclerView。使用原始视图时,这可以正常工作。
但是,当扩展 RecyclerView创建自己的自定义视图以添加一些功能时,它只是在Android Studio的布局预览中显示了空白区域。
扩展视图时,如何使用视图的所有布局预览内容?
我的视图如下所示:
class TestRecyclerView(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int
) : RecyclerView(context, attrs, defStyle) { }
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?