相关疑难解决方法(0)

什么是AndroidX

我正在阅读关于Android的房间库.我看到他们改变包装androidandroidx.我不明白.请有人解释一下.

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

204
推荐指数
8
解决办法
10万
查看次数

如何从XML设置RecyclerView app:layoutManager =""?

如何从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)

xml android android-recyclerview androidx

143
推荐指数
4
解决办法
7万
查看次数

在android studio中预览水平recyclerview

我发现了如何使用预览列表项

tools:listitem="@layout/my_item_layout"
Run Code Online (Sandbox Code Playgroud)

但android studio正在将recyclerview预览为垂直列表.有没有办法告诉Android Studio我会附加一个水平,LinearLayoutManager以便它可以预览水平列表?

android android-studio android-recyclerview

40
推荐指数
4
解决办法
6726
查看次数

有没有办法在Android Studio编辑器中显示RecyclerView的内容预览为网格?

当我将RecyclerView添加到布局时,它以垂直顺序显示为列表视图.我正在使用tools:listitem这个.有没有办法,它在Android Studio编辑器中显示为网格而不是列表?

android android-studio android-recyclerview

27
推荐指数
5
解决办法
6635
查看次数

工具:RecyclerView项目的文本

我知道你设置的时候

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

6
推荐指数
1
解决办法
2337
查看次数

是否可以在布局编辑器中以水平方向显示RecyclerView预览?

RecyclerView以垂直方向显示,并且无法设置此属性,因为方向属于LinearLayoutManager对象.有什么方法可以模拟HORIZONTAL布局?

无论如何,linearLayoutManager在代码中创建的设置为HORIZONTAL.

llm.setOrientation(LinearLayoutManager.HORIZONTAL);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android android-layout android-recyclerview

5
推荐指数
2
解决办法
1597
查看次数

tools:listitem用于扩展RecyclerView的自定义视图

我尝试用来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)

有任何想法吗?

android android-layout android-studio android-recyclerview

4
推荐指数
1
解决办法
506
查看次数