我尝试在视图上实现16:9的宽高比PercentRelativeLayout.
所以我把这行放在build.gradle文件中: compile 'com.android.support:design:23.0.1'
我用这个布局:
<android.support.percent.PercentRelativeLayout
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">
<ImageView
android:layout_width="match_parent"
app:layout_aspectRatio="178%"
android:scaleType="centerCrop"/>
</android.support.percent.PercentRelativeLayout>
Run Code Online (Sandbox Code Playgroud)
问题:
'layout_height' should be defined为了ImageView.Error:(15) No resource identifier found for attribute 'layout_aspectRatio'.那有什么不对?
android android-layout android-constraintlayout android-percentrelativelayout
在用于ConstraintLayout.One的android studio SDK工具中有两个选项ConstraintLayout for android,另一个是Solver for ConstraintLayout.
这两个选项有什么区别?
我相对于布局指南放置了很多项目,并希望几乎相对于此布局指南定位一个新项目.
我尝试使用负布局边距但没有成功.
我正在编写一个自定义视图,以便能够使用自定义XML属性根据这些属性设置视图的边距和大小,一切正常,直到我到达ConstraintLayout的子项获得其边距和大小由自定义值确定的部分.边距没有任何区别,视图保留在其父ConstraintLayout的左上角.可能是什么问题呢?(图像应距离屏幕边界500PXs)
if (hasCustomWidth || hasCustomHeight || hasCustomTopMargin || hasCustomRightMargin || hasCustomBottomMargin || hasCustomLeftMargin) {
if(((ViewGroup)getParent()) instanceof LinearLayout) {
LinearLayout.LayoutParams newLayoutParams = new LinearLayout.LayoutParams((int) Math.round(customWidth), (int) Math.round(customHeight));
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) newLayoutParams;
marginLayoutParams.setMargins((int) Math.round(customLeftMargin), (int) Math.round(customTopMargin), (int) Math.round(customRightMargin), (int) Math.round(customBottomMargin));
setLayoutParams(newLayoutParams);
} else if(((ViewGroup)getParent()) instanceof ConstraintLayout) {
ConstraintLayout parentConstraintLayout = (ConstraintLayout)CustomAppCompatImageView.this.getParent();
ConstraintLayout.LayoutParams newLayoutParams = new ConstraintLayout.LayoutParams((int) Math.round(customWidth), (int) Math.round(customHeight));
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(parentConstraintLayout);
constraintSet.connect(CustomAppCompatImageView.this.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, 500);
constraintSet.setMargin(CustomAppCompatImageView.this.getId(), ConstraintSet.LEFT, 500);
setLayoutParams(newLayoutParams);
constraintSet.applyTo(parentConstraintLayout);
parentConstraintLayout.invalidate();
} else {
throw new …Run Code Online (Sandbox Code Playgroud) 我正在尝试从RelativeLayout迁移到ConstraintLayout,但我在将AdMob AdView添加到底部以及其上方的其余内容时遇到问题.例如,使用RelativeLayout就是这么简单.您只需要放置android:layout_alignParentBottom="true"AdView和android:layout_above="@+id/adView"包含内容的视图.
我试图了解如何使用ConstraintLayout而不是RelativeLayout将此示例代码和这两行代码迁移到等效代码.
拜托,有人可以帮我解决这个问题吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@android:color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adView"/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
ads:adSize="BANNER"
ads:adUnitId="@string/ad_id_banner">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我app:layout_constraintBottom_toTopOf="@+id/adView"在adView上面和adView app:layout_constraintBottom_toBottomOf="parent"上测试了我想要的东西,但它不起作用,因为这些东西不在它后面的adView之上.此外,adView不会居中.这非常令人沮丧.
android android-layout android-relativelayout android-constraintlayout
我只是在编辑文本的高度达到布局高度的末尾时,我试图在编辑文本中显示滚动条.如果我输入/添加空格,但是当我的文本到达编辑文本宽度的末尾时,它会导致问题.一旦我的文本到达我的编辑文本宽度的末尾,它就开始向我显示滚动条,而当我到达屏幕的(高度)结束时它应该显示.
<?xml version="1.0" encoding="utf-8"?>
<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">
<EditText
android:id="@+id/editFeedback"
android:layout_width="0dp"
android:layout_height="0dp"
android:bufferType="spannable"
android:gravity="top"
android:hint="Some text"
android:inputType="textCapSentences|textMultiLine"
android:minHeight="120dp"
android:overScrollMode="ifContentScrolls"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:selectAllOnFocus="true"
android:textIsSelectable="true"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/buttonSend"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="@id/guidelineStart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed"
tools:text="" />
<Button
android:id="@+id/buttonSend"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="Send"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="@+id/barrierEnd"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintTop_toBottomOf="@+id/editFeedback" />
<TextView
android:id="@+id/Footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="100dp"
android:text="This is a footer"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="8dp" />
<android.support.constraint.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="8dp" />
<android.support.constraint.Barrier
android:id="@+id/barrierEnd"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 直到昨天一切都很好。今天当我打开系统时,我突然收到错误:
java.lang.IllegalStateException: function = <anonymous>, count = 3, index = 3
Run Code Online (Sandbox Code Playgroud)
与“内部编译器错误”一起运行我的项目。
我尝试更新我的 gradle 版本和 gradle 插件版本,以及我使用过的依赖项,但是没有用。
我该如何解决这个问题?
这些是我使用过的依赖项:
def lifecycle_version = "2.3.1"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.drawerlayout:drawerlayout:1.1.1"
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
implementation "androidx.navigation:navigation-ui-ktx:2.3.5"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.shawnlin:number-picker:2.4.11'
implementation 'com.karumi:dexter:6.2.1'
implementation 'com.github.IslamKhSh:CardSlider:1.0.1'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:3.0.0-RC2'
// Lottie dependency
implementation "com.airbnb.android:lottie:3.7.0"
//Autostart settings open
implementation 'com.thelittlefireman:AppKillerManager:2.1.1'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0' …Run Code Online (Sandbox Code Playgroud) android compiler-errors kotlin android-constraintlayout android-jetpack-compose
我最近开始使用ConstraintLayout.正如我发现的那样,大多数功能都非常简单,并且在文档中对样本,文本和视频教程等进行了详细解释.
我想到的是如何尽可能优雅地解决这个"谜题"?
如您所见,在布局的右侧部分,我有多个左对齐的视图.在最后一行中,有3个视图水平对齐(它们也在彼此之间对齐).问题是:如果我将第一个View的可见性从该行设置为GONE,则另外两个(在同一行中)按预期向左移动,但下面的那个(垂直对齐中的最后一行)超过该行(因为它constraintTop属性设置为View设置为GONE的底部.
我能想到的唯一解决方案是使用ViewGroup对这3个视图进行分组,并将约束添加到最后一行View.
我错过了ConstraintLayout上的一些属性,这对我的情况有帮助吗?如果在GONE View中设置其中一个,可能会出现某种后退(或多个)约束?
对不起,如果我的解释看起来很深奥,也许图片会帮助你更多:)
LE: 增加了布局:https://gist.github.com/DooruAdryan/7e7920a783f07b865489b1af0d933570
我正在使用以下组件进行简单的列表活动:EditText,RecyclerView,ProgressBar和Textview.一切都运行得很好,除了与EditText重叠并且"超出"屏幕底部的RecyclerView,所以最后一项被部分剪掉(参见截图).我做错了什么?
主要活动:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="jacopo.com.flickrgallery.GalleryActivity">
<EditText
android:id="@+id/search_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:hint="search by tag..."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/gallery_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<android.support.v7.widget.RecyclerView
android:id="@+id/gallery_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text" />
<TextView
android:id="@+id/gallery_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search_text"
tools:text="error" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
android android-layout android-recyclerview android-constraintlayout
我在布局中使用的是androidx.constraintlayout.widget.ConstraintLayout,它没有显示链,也无法拖动任何小部件。我只是输入要使用的约束。
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="112dp"/>
Run Code Online (Sandbox Code Playgroud)
这是androidx约束布局的示例屏幕截图: androidx.constraintlayout.widget.ConstraintLayout
但是当我尝试切换回android.support.constraint.ConstraintLayout时,我可以看到它
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="112dp"/>
Run Code Online (Sandbox Code Playgroud)
这是支持constraintLayout的示例屏幕截图: android.support.constraint.ConstraintLayout
这是错误还是什么?
我当前的解决方案是从:
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
Run Code Online (Sandbox Code Playgroud)
至
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
Run Code Online (Sandbox Code Playgroud)
但这不能解决我的问题,因为我不想使用支持。
android android-constraintlayout constraint-layout-chains androidx