java - 使用网格布局将不同长度的垂直 TextView 与相同的右边缘对齐

标签 java android layout textview android-gridlayout

enter image description here

我想使用网格布局制作该图像的细节部分,但我面临的问题是,当 TextView 的长度不同时,它们不会在彼此下方结束。我的 TextView 起点相同,结束点不同,但在该图像布局中,它们在彼此下方结束。 例如,Vol 的值比 low 的值具有更多位数,但两者具有相同的终点。 我如何使用网格布局来实现这一点? 这是我的代码

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="4"
android:rowCount="4"
android:padding="8dp"
android:orientation="horizontal"
android:background="@drawable/toolbar_background">

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:text="Open"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:text="36.40"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="10dp"
    android:text="MktCap"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:text="33.39B"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginTop="10dp"
    android:text="High"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:text="36.95"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:text="52WkHigh"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:text="42.31"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginTop="10dp"
    android:text="Low"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:text="36.08"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:text="52WkLow"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:text="26.15"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginTop="10dp"
    android:text="Vol"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:text="19.66M"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:text="P/E"/>

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="10dp"
    android:text="1.25"/>

最佳答案

使用

android:layout_gravity="right"

在所有您想要在彼此下方结束的 TextView 中。 你也可以添加这个

 android:gravity="right"

关于java - 使用网格布局将不同长度的垂直 TextView 与相同的右边缘对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38037363/

相关文章:

java - 将 Spring 参数添加到 VSCode Debug launch.json

android - 选择 Android 库的构建变体的 Gradle 脚本

android - 如何覆盖在应用程序消息中的深层链接中打开 Appboy 网络 Activity 的行为

magento - 从观察者覆盖整个magento布局

android - 如何在单个 RecyclerView 中实现 RecyclerView?

java - Spring Batch Kafka Kafka 到数据库作业

java - 在 Play Framework 中调用 renderBinary() 后关闭 InputStream

html - 在IE和FF中定位-浏览器布局不一致的box fix解决方案

java - 将一些字节的十六进制字符串表示转换成Java中的字节数组

android - RecyclerView重叠没有阴影