Android上的自适应布局 [英] Responsive layout on Android
本文介绍了Android上的自适应布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在布局中有三个元素,两个元素之间有一个TextViews和一个ImageView.我正在尝试实现这种行为:
I have three elements in layout, two TextViews and one ImageView between them. I'm trying to achieve this behavior:
- 图像(箭头)有9个补丁
- 图像尽可能宽
- 图像设置了最小宽度
- 左右文本随着较长的文本而变宽,但仅满足图像的minWidth,然后出现新行
以下是Android Studio布局预览中的一些屏幕截图,这些截图是使用不同的布局获得的.
Below are few screenshots from Android Studio layout preview, gained with different layouts.
我尝试过的事情:
- 相对布局:以图片为中心,设置了minWidth,将文本设置为"RightOf/toLeftOf"
- 相对布局:图像已设置为"RightOf/toLeftOf"
- 约束布局:约束箭头"从图像到文本
- 约束布局:约束箭头"从文本到图像
- 线性布局:使用权重(没有真正的响应能力)
我总是得到的:
我想要的对我来说似乎很简单,但我做不到.我是否想念某些东西还是真的不可能?预先谢谢你.
What I want seems quite straightforward to me but I cannot do it. Am I missing something or is it really impossible? Thank you in advance.
推荐答案
这里是通过创建水平链通过ConstraintLayout完成的另一个答案.
Here is one more answer done via constraintLayout by creating horizontal chains.
根据您的要求更新
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/left_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="ajn sdhbch chf nbhjgvbf vkjf vhf bvihfijnvj vfknvv ihvb jnvkjnfv kjnvfn"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/imageView6"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/left_tv"
app:layout_constraintRight_toLeftOf="@+id/right_tv"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_next_button" />
<TextView
android:id="@+id/right_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imageView6"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
这篇关于Android上的自适应布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文