android - LinearLayout 中的自动缩放元素
问题描述
我有一个简单的片段,我希望它看起来像这个图像:image。
我的片段代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
tools:context=".SignFragment">
<android.support.constraint.ConstraintLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/wrapper_padding">
<ImageView
android:id="@+id/imageOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:srcCompat="@drawable/example" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp">
<TextView
android:id="@+id/infoMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/info_message_example"
android:textColor="@color/colorInfoMessage"
android:textSize="25sp" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
但我的片段看起来像这样的图像:image。在景观变体上,文本被隐藏。
我尝试在<LinearLayout/>
或其他元素上添加一些属性。当我在第一个 ConstraintLayout 上添加 android:layout_weight="1" 时,我得到了这个。
横向变化是正确的,但纵向方向被破坏了。
如何更改我的 xml 文件以获得正确的结果?
解决方案
要为纵向和横向模式创建单独的片段设计,请创建两个不同的XML
文件,一个用于纵向模式设计,另一个用于横向模式。放入layout-port
并layout-land
文件夹里面res folder
。
例子:
res/layout-port [Portrait Mode; default]
main.xml
res/layout-land [Landscape Mode]
main1.xml
参考文档:http: //developer.android.com/training/basics/supporting-devices/screens.html
推荐阅读
- java - 发现全局预期 com.package.sameobj 的非法类 com.package.sameobj
- javascript - 警报框计数器不增加
- java - 可以/应该多久使用一次请求?
- r - R 中的时间序列交叉验证:使用 tsCV() 和 tslm()-Multiple 模型
- mysql - CREATE TABLE 电影数据库的 MySQL 问题
- javascript - 从 Firebase 集合中查询数据
- python - 运行bash命令后如何将shell输出输入python
- python - DLL 加载失败:找不到指定的模块 PYTHON
- javascript - 承诺 {
} 使用异步等待 - c - 通过多个函数访问数组