android - 如何使用线性布局将视图定位到边框
问题描述
我需要将视图放在边框中,以便它位于布局的最左侧,并希望将其应用于所有不同手机的尺寸!?
例子:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="285dp"
android:text="@string/textView"
android:textSize="28sp" />
</LinearLayout>
现在此代码输出以下 Layout,我需要这样做而不使用边距来匹配所有手机尺寸
解决方案
您可以将其添加到
android:layout_gravity="right"
您的.TextView
android:orientation="vertical"
LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/textView"
android:textSize="28sp" />
</LinearLayout>
我希望它会和你一起工作。
推荐阅读
- javascript - 不明白我使用 parseFloat 时发生了什么
- vue.js - 在 Vue 模板中渲染表格
- c# - POST csv 文件 httpclient C# 和 application/x-www-form-urlencoded
- html - 使用 Ubuntu 时如何从 angular4 中删除哈希 (#)
- asp.net - Angular 5.2 使用 Asp.net core 2.1 更新到 Angular 6 Visual Studio mac 7.5.2
- r - Change the colour of a subset of labels in barplot R
- cloudcaptain - boxfuse 的默认配置参数
- java - 如何自定义 Spring Boot 横幅?
- ios - 如何从 iMessage 应用扩展添加应用内购买以销售 Stickes
- javascript - 来自 HTML 属性的 Javascript 数组未按预期执行功能