我试图使用约束布局链垂直居中两个文本视图.我知道我可以将文本布局包装成线性布局,但我想尝试新的链特征.当我构建我的项目时,虽然我收到错误,Error:(28, 50) No resource found that matches the given name (at 'layout_constraintBottom_toTopOf' with value '@id/item_school_location').
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="72dp">
<ImageView
android:id="@+id/item_school_logo"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:contentDescription="@string/item_school_logo_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
<TextView
android:id="@+id/item_school_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="72dp"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"
app:layout_constraintBottom_toTopOf="@id/item_school_location"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintVertical_chainPacked="true" />
<TextView
android:id="@+id/item_school_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="72dp"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/item_school_name" />
</android.support.constraint.ConstraintLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
有谁知道是什么导致了这个错误?
我有一个小问题layout_constraintVertical_weight,我试图使两个TextView共享分配的区域中可用的垂直空间,但是没有我的手动分配就不会发生。我试过增加0dp高度,但这是行不通的,但是对于宽度,它可以完美地工作。这是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for a single list item -->
<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="@dimen/list_item_height"
android:background="@color/tan_background">
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/miwok_text_view"
android:layout_width="0dp"
android:layout_height="44dp"
android:background="@color/category_colors"
app:layout_constraintLeft_toRightOf="@+id/image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="1"
tools:text="text1" />
<TextView
android:id="@+id/default_text_view"
android:layout_width="0dp"
android:layout_height="44dp"
android:background="@color/category_numbers"
app:layout_constraintLeft_toRightOf="@+id/image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_weight="1"
tools:text="text2" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是布局外观的img:https : //i.stack.imgur.com/ZOs9y.png
我正在开发一个 android 应用程序,我在其他视图下面有一个 webview。
整个内容不适合屏幕,所以我想启用一些滚动。
我的布局文件如下所示:
<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:background="@color/white"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView .../>
<TextView .../>
<TextView .../>
<TextView .../>
<WebView
android:id="@+id/about_detail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:textSize="14sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/contactInformation"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我应该在 ConstraintLayout 周围使用 Scrollview,或者我该怎么做?
android scroll android-webview android-scrollview android-constraintlayout
约束集connect的官方文档说:https://developer.android.com/reference/android/support/constraint/ConstraintSet.html#connect (int,int,int,int,int)
void connect (int startID,
int startSide,
int endID,
int endSide,
int margin)
Run Code Online (Sandbox Code Playgroud)
限制的边际(保证金必须是积极的)
根据我的理解,如果我想从左到右连接两个视图,那么这个边距是左边距.
//从左到右
constraintset.connect(textView.id,ConstraintSet.LEFT,previousTextViewId,ConstraintSet.RIGHT,10)
Run Code Online (Sandbox Code Playgroud)
然后10是左边距.我对吗?我已经实现了这个概念,但即使没有右边或左边也没有设置边距.我错过了什么?
我如何View放在另一个Viewin后面ConstraintLayout?基本上我想实现这个:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
当视图 1 在 Z 轴上位于视图 2 后面时。
android android-layout android-studio android-constraintlayout android-studio-3.0
我目前正在尝试ConstraintLayout我们的项目.
我想要实现的布局可以简化如下:
布局顶部有两个视图(比如TopA和TopB),还有另一个视图(比如BottomC)位于它们下面.
TopB具有可变高度,在不同情况下,TopB的高度可能比TopA更大或更小.
我的问题是:如何将BottomC约束到具有较大高度的顶视图的底部,以便BottomC不会被具有较大高度的视图重叠.(下面的截图)
我可以通过将TopA和TopB添加到额外ViewGroup(LinearLayout例如)并将BottomC约束到底部来实现ViewGroup.但是有可能在不引入额外层的情况下实现这一目标ViewGroup吗?
我想移动我的位置,ImageView这样它会距离ConstraintLayout(父对象)一半。LinearLayout
我所拥有的是图像,应该按照图片上的说明进行裁剪,因此图像的仅按钮侧应显示在实际设备上。其他部分应切除。
这是我的布局的一部分。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="71dp"
android:layout_height="71dp"
android:src="@drawable/someImage"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
那么,有什么好办法吗?
我试图ImageButton在ConstraintLayout上使它们之间具有相等的间距为5 ,但是在锚定它们并使其变得容易时遇到了一些问题,例如:
我的xml代码:
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/sheet_shadow"
android:padding="5dp">
<ImageButton
android:id="@+id/btn1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_40"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert" />
<ImageButton
android:id="@+id/btn2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_40"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn1"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert" />
<ImageButton
android:id="@+id/btn3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_40"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn2"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert" />
<ImageButton
android:id="@+id/btn4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="18dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_40"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn5"
app:layout_constraintStart_toEndOf="@+id/btn3"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert" />
<ImageButton
android:id="@+id/btn5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_40"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" …Run Code Online (Sandbox Code Playgroud) 学习ConstraintLayout并遇到此问题,即使选择了文本视图,基线约束句柄也不可见。
使用Android Studio 3.4.1,Show All Constraints被选择。
摇篮:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 28
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)