【发布时间】:2020-05-09 12:22:54
【问题描述】:
我有一个巨大的布局文件,其中包含一个平面约束布局。
我有相同的android.support.constraint.Group 元素。我想将它们移动到一个单独的文件中,然后像 <include layout="@layout/selection_group"/> 那样包含它们
我面临的问题是我在文件selection_group.xml 中的组在 Android Studio 中没有正确预览。有没有办法让 Android Studio 直接在文件中预览它或以不同的方式包含它们?
selection_group.xml
<layout 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.support.constraint.Group
android:id="@+id/top_bar_config_one_background_group"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/top_bar_background_with_border_fx"
android:clickable="true"
app:constraint_referenced_ids="top_bar_config_one,top_bar_tooth_one"
app:layout_constraintBottom_toBottomOf="@+id/top_bar_container_background"
app:layout_constraintLeft_toLeftOf="@+id/top_bar_container_background"
app:layout_constraintRight_toLeftOf="@+id/top_bar_config_two"
app:layout_constraintTop_toTopOf="@+id/top_bar_container_background" />
<ImageView
android:id="@+id/top_bar_config_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:scaleType="center"
android:src="@drawable/ic_height_over_sea_100x26"
app:layout_constraintBottom_toTopOf="@+id/top_bar_tooth_one"
app:layout_constraintLeft_toLeftOf="@+id/top_bar_container_background"
app:layout_constraintRight_toLeftOf="@+id/top_bar_config_two"
app:layout_constraintTop_toTopOf="@+id/top_bar_config_one_background_group" />
<ImageView
android:id="@+id/top_bar_tooth_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@drawable/ic_tooth_auto_40x40"
app:layout_constraintBottom_toBottomOf="@+id/top_bar_config_one_background_group"
app:layout_constraintLeft_toLeftOf="@+id/top_bar_container_background"
app:layout_constraintRight_toLeftOf="@+id/top_bar_config_two" />
<?xml version="1.0" encoding="utf-8"?>
</layout>
我不想将多个约束布局嵌套在一起。我认为selection_group.xml 中的根<layout> 视图已经过优化,不会影响性能?我的目标是减少冗余代码而不影响性能
【问题讨论】:
-
您是否尝试使缓存无效并重新启动android studio?你也可以看看这个线程。 stackoverflow.com/questions/34499839/… 如果这对您的事业有帮助。
标签: android android-constraintlayout