标签: android-tools-namespace

Android:如何使用包含布局的工具

我如何使用工具:

xmlns:tools="http://schemas.android.com/tools"
Run Code Online (Sandbox Code Playgroud)

<include>

我有一个布局A,我使用工具用测试数据填充所有文本字段.我有布局B使用include到布局中的复制它.但是,当我这样做时,我没有看到测试数据A.

如何查看A包含的测试数据B

*两种布局都有xmlns:tools="http://schemas.android.com/tools,我甚至把它推到了布局标签上.

xml android android-layout android-tools-namespace

11
推荐指数
1
解决办法
9216
查看次数

如何通过tools:listitem使用androidx.recyclerview.widget.RecyclerView?

如何搭配androidx.recyclerview.widget.RecyclerView使用tools:listitem?我有这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
    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:id="@+id/recyclerViewActors"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
    tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
    tools:listitem="@layout/list_item_actor"
    tools:itemCount="5"
    tools:orientation="horizontal"
    tools:scrollbars="horizontal"
    tools:spanCount="2"/>
Run Code Online (Sandbox Code Playgroud)

但“ 设计”选项卡不显示预览:

在此处输入图片说明

而且,如果我androidx.recyclerview.widget.RecyclerView将此布局更改为ListView,则预览工作正常:

在此处输入图片说明

android preview android-recyclerview android-tools-namespace androidx

7
推荐指数
1
解决办法
2万
查看次数

工具: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
查看次数

如何更改底部导航活动的菜单布局文件的设计选项卡的视图(工具:showIn)

我只想将我的设计视为底部导航视图,因此我通过设置tools:showIn="bottom_navigation_view"menu.xml文件上尝试了以下操作,但它对我的设计视图选项卡没有任何影响

我不想要的菜单视图的图像

在此处输入图片说明

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="bottom_navigation_view">

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_home_black_24dp"
        android:title="@string/title_home" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@drawable/ic_dashboard_black_24dp"
        android:title="@string/title_dashboard" />

    <item
        android:id="@+id/navigation_notifications"
        android:icon="@drawable/ic_notifications_black_24dp"
        android:title="@string/title_notifications" />

</menu>
Run Code Online (Sandbox Code Playgroud)

所以请建议我这样一个有价值的工具:showIn可以工作。

android android-layout android-xml android-menu android-tools-namespace

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

工具命名空间android listitem

我正在尝试使用Android Studio中的"工具"命名空间功能.ListView出于设计目的,我正在尝试使用虚拟列表项填充.这里的链接说tools:listitem="@android:layout/<filename>"应该这样做.

但出于某种原因,Android Studio一直在显示Layout android:<filename> does not exist.我正在尝试为其找到解决方案,因此我不必一次又一次地使用虚拟值来运行我的应用程序进行测试.

我可能会忽略一些非常愚蠢的东西,所以请原谅我.这是我现在拥有的:

<ListView
    android:id="@+id/controllerProfiles"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="20dp"
    tools:listitem="@android:layout/profiles_list_item"/>
Run Code Online (Sandbox Code Playgroud)

我有一个文件profiles_list_item.xmlres/layout.任何建议或替代?

android listview android-tools-namespace

5
推荐指数
1
解决办法
4626
查看次数

工具:指向多个活动的上下文链接

我读过有关tools:context 的内容,发现它在开发时非常有用,因为它可以帮助我了解我使用了当前 Xml 的哪些活动。

我的问题是:

我有 2 个活动,使用相同的 Xml 文件(重复使用相同的layout.xml文件),但我无法使用tools:context

如何tools:context在 Xml 中使用链接 2 个活动?

我努力了:

<?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="wrap_content"
    tools:context="com.example.mytestapp.MainActivity,com.example.mytestapp.Main2Activity">

    <!-- Other Layouts Here -->

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这给了我红线

还尝试使用:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:tools2="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.example.mytestapp.MainActivity"
    tools2:context="com.example.mytestapp.Main2Activity">

    <!-- Other Layouts Here -->

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这不会给出红线,但是当我运行它们时,我收到以下错误:

Error:(2) error: duplicate attribute.
Error:(2) duplicate attribute.
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-tools-namespace

5
推荐指数
0
解决办法
1981
查看次数