在线性布局内的 ScrollView 内并排对齐 TextView

2024-05-15

我有一个带有滚动视图的线性布局,我想保留它的当前格式 - 但只需将 textView2a 和 textView3a 并排放置,而不会破坏我当前的布局格式。

我已经包含了我最近的尝试 - 但它们似乎不正确。

提前致谢!

-Java菜鸟

当前有效的 XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/groupScrollView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Throw &apos;Em Up"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by User1"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bulls On Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by Rage Against the Machine"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=" Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="678,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />


            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>
        </LinearLayout>


    </ScrollView>

</LinearLayout>

尝试添加并排对齐:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/groupScrollView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Throw &apos;Em Up"
                android:textAppearance="?android:attr/textAppearanceMedium" />
  <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by DJ Generic"
                android:layout_toLeftOf="@+id/textView3a"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />
    </RelativeLayout>
            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bulls On Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by Rage Against the Machine"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="CNN Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="678,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />          

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

尝试替换这个:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView2a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/textView3a"
        android:text="by DJ Generic"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="100,000 views"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>

By this:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView2a"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:layout_toLeftOf="@+id/textView3a"
        android:text="by DJ Generic"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3a"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:text="100,000 views"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

让我知道这是否是您想要做的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在线性布局内的 ScrollView 内并排对齐 TextView 的相关文章

  • 使用busybox在后台安装apk

    我可以在 root 设备上使用 busybox 在后台安装 apk 吗 我看到类似的东西 但它不起作用 process install CommandCapture command new CommandCapture 0 chmod 77
  • putExtra() 和 setData() 之间的区别

    putExtra 和 setData 有什么区别 我已经阅读了 android 文档 但没有太大帮助 还有之前的一个问题Intent setData 与 Intent putExtra https stackoverflow com que
  • 如何在android中批量插入sqlite

    我正在使用 SQLiteOpenHelper 进行数据插入 我需要插入2500个id和2500个名字 所以花费了太多时间 请任何人帮助我如何减少插入时间 我们可以一次插入多条记录吗 任何人都可以帮助我 先感谢您 代码 public clas
  • app-release-unsigned.apk 未签名

    我在 github 上下载了 Android 应用程序的 zip 文件 并尝试运行它 但出现一个包含此消息的对话框 app release unsigned apk is not signed Please configure the si
  • Firebase Messaging FCM 在可配置的时间间隔内分发

    当您使用 FCM 向给定应用程序的所有设备发送推送时 这可能会导致许多用户同时打开他们的应用程序 从而导致大量服务器轮询 从而导致负载峰值 有没有一种方便的方法可以在给定的时间间隔内分发消息以进行计划推送 最后 我们找到了一种可能的方法 通
  • Golang 结构的 XML 和 JSON 标签?

    我有一个可以根据 HTTP 请求标头输出为 JSON 或 XML 的应用程序 我可以通过将正确的标签添加到我正在使用的结构中来实现正确的输出 但我不知道如何为 JSON 和 XML 指定标签 例如 序列化以纠正 XML type Foo s
  • startActivityForResult中的requestCode是什么意思

    我想知道我是否正确理解 requestCode 的概念 这个整数的用途是什么 我将其设置为哪个整数有关系吗 private static int CAMERA REQUEST 谢谢 requestCode 可帮助您识别您从哪个 Intent
  • 在没有 BluetoothManagerCallback 的情况下调用 getBluetoothService

    我正进入 状态getBluetoothService called with no BluetoothManagerCallback在我的 Android 应用程序中经常出现错误 我不知道是什么原因导致这个或任何有关蓝牙管理器回调的事情 谁
  • Android WebView文件上传

    我正在开发一个 Android 应用程序 基本上它是一个WebView和一个进度条 Facebook 的移动网站 m facebook com 已加载到WebView 当我单击 选择文件 按钮上传图像时 没有任何反应 我已经尝试了所有的解决
  • 删除 XML 中的指定标签 (notepad++)

    我的 GPS 轨迹有一个 非常 大的 XML 文件 它是这样构建的
  • 从 Android 访问云存储

    我一直无法找到任何有关如何从 Android 应用程序使用云存储的具体文档 我确实遇到过这个客户端库 https cloud google com storage docs reference libraries然而 Google Clou
  • 如何使用共享首选项在两个 Android 应用程序之间共享数据?

    我有两个应用程序 App1 和 App2 我想使用共享首选项在 App1 中保存数据并在 App2 中访问 反之亦然 我可以在 App1 中保存数据并在 App2 中访问数据 但反之则不行 这就是我现在正在做的 在清单中 android s
  • 推特更新状态

    我正在通过 twitter4j 将 Twitter 集成到 Android 我可以成功阅读我发布的推文 现在我试图用它发布推文 但我不能 我收到如下奇怪的警告 02 01 16 28 43 298 WARN System err 729 4
  • 在循环中按名称访问变量

    我正在开发一个 Android 项目 并且有很多可绘制对象 这些绘图的名称都类似于icon 0 png icon 1 png icon 100 png 我想将这些可绘制对象的所有资源 ID 添加到整数 ArrayList 中 对于那些不了解
  • Android项目中使用java获取电脑的IP地址

    我在用ksoap2 android http code google com p ksoap2 android 我需要使用java获取IP地址 这样我就不必每次都手动输入它 我所说的 IP 地址是指 例如 如果我这样做ipconfig使用命
  • Android Jetpack Compose 尺寸随持续时间变化的动画

    如何在 Jetpack Compose 中添加内容大小更改动画的持续时间 尝试使用Modifier animateContentSize 并通过动画规格具有持续时间 但它只是突然进入或退出 没有观察到持续时间 Column Modifier
  • android 中的 java.net.URL ..新手问题

    我是java新手 正在尝试android开发 以下代码生成 malformedURLException 有人可以帮助我识别异常吗 任何提示都会非常有帮助 package com example helloandroid import and
  • 如何检测日期选择器对话框的取消单击?

    我正在使用以下 日期选择器的示例 http developer android com guide tutorials views hello datepicker html http developer android com guide
  • 如何解决android程序中的警告“从不本地读取”

    为什么我收到警告说 The field testscreen ScaleAnimToShow mVanishAfter is never read locally testscreen java testscreen src com tes
  • Android Google 地图无法在当前主题中找到样式“mapViewStyle”

    添加谷歌地图视图时 我扩展了MapView 使用xml编辑器将其添加到活动中 并将我的谷歌地图api密钥手动添加到布局xml文件中 我的权限在清单文件中允许互联网 我想知道的是 在 xml 编辑器中 我收到错误 无法在当前主题中找到样式 m

随机推荐

  • 如何从 nltk 下载器中删除数据/模型?

    我在 python3 NLTK 中安装了一些 NLTK 包 通过nltk download 尝试过它们 但不需要它们 现在想删除它们 我怎样才能删除例如包large grammars来自我的 NLTK 安装 我不想删除完整的 NLTK 安装
  • 为什么自类型类可以声明类

    我知道 Scala 只能混合特征 这对于依赖注入和蛋糕模式是有意义的 我的问题是为什么我仍然可以声明一个需要另一个 类 但不需要特征的类 Code class C class D self C gt 这仍然编译成功 我认为它应该编译失败 因
  • 在父类中访问子类变量

    我有一个父类和一个继承的子类 我想知道如何访问我的父类中的子类变量 我尝试了这个但失败了 class Parent object def init self print x class Child Parent x 1 x Child Er
  • 如何仅突出显示嵌套表的最里面的表行?

    我有几个嵌套表 我想突出显示鼠标指针下方的最里面的行 我怎样才能做到这一点 一些提示 我使用嵌套表来显示递归表格数据 表可以嵌套 10 层 嵌套正如您所期望的那样 table tr td table tr td table tr td 可能
  • Android View Canvas onDraw 未执行

    我目前正在开发一个自定义视图 它在画布上绘制一些图块 这些图块是从多个文件加载的 并将在需要时加载 它们将由 AsyncTask 加载 如果它们已经加载 它们只会被绘制在画布上 这工作正常 如果加载了这些图片 AsyncTask 就会触发v
  • 需要一些在自定义 AngularJS 标签中绑定属性的示例

    我正在尝试创建类似于以下内容的自定义标签
  • 如何从 Mac OS X 中完全删除 Eclipse(包括设置和插件)?

    我的 Eclipse 与 GAE 损坏并且工作异常 所以我从Application文件夹中删除了Eclipse 但是留下了垃圾 我重新下载了全新的 eclipse 但它以旧设置运行 并且损坏的 GAE 结构仍然存在 如何从 Mac 上完全删
  • laravel中过滤后如何导出excel?

    我想仅导出视图刀片中过滤的数据 我正在使用 Laravel 7 和 maatwebsite excel 3 1 和 PHP 7 4 2 我浏览了文档并应用了这个 View a href class btn btn success i cla
  • 实现 Index 特征以返回非引用的值

    我有一个想要实现的简单结构Index 但作为 Rust 的新手 我在借用检查器方面遇到了许多麻烦 我的结构非常简单 我想让它存储一个起始值和步骤值 然后当由usize它应该返回start idx step pub struct MyStru
  • GoLang ssh:尽管将其设置为 nil,但仍出现“必须指定 HosKeyCallback”错误

    我正在尝试使用 GoLang 连接到远程服务器 在客户端配置中 除了用户和密码之外 我将 HostKeyCallback 设置为 nil 以便它接受每个主机 config ssh ClientConfig User user HostKey
  • 如何避免刷新页面时重新执行上次表单提交操作?

    我正在从事用 JSF 开发的项目 每当我们刷新 JSF 页面时 就会重新执行最后一个操作事件 例如 当我提交表单以删除列表的条目并刷新结果页面时 列表中同一位置的另一个条目也会被删除 这是如何引起的以及如何解决 我在 faces confi
  • SQL Server 中的嵌套事务

    sql server 允许嵌套事务吗 如果是的话那么交易的优先级是什么 来自 SQL Server 上的 MSDN 文档 嵌套交易 http msdn microsoft com en us library ms189336 SQL 90
  • 二维数组的 MPI 数据类型

    我需要将一个整数数组的数组 基本上是一个二维数组 从根传递给所有处理器 我在 C 程序中使用 MPI 如何声明二维数组的 MPI 数据类型以及如何发送消息 我应该使用广播还是分散 你需要使用播送 http www netlib org ut
  • 获取 byte[]

    我有一个 html 画布 如下所示 output is a base64string of image data var oldImage new Image oldImage onload function var resizeRatio
  • window.open 使用 css 样式

    我想设计我的 window open 目前 我的网页上有一些项目由于解析了某个类而打开 然后在新窗口中打开指定的文本 我想更改字体大小 字体和填充等 这是我的 JavaScript 代码
  • ARM Chromebook 上的 Android 开发环境?

    我尝试了多次安装和使用安卓工作室 https developer android com studio index html on an ARM Chromebook C100P https archlinuxarm org platfor
  • 配置 Ping Federate 和 Spring SAML 对应用程序进行身份验证

    我在运行 Windows Server 2008 R2 SP1 English 64Bit Base 2014 04 09 的 AWS EC2 上安装了 PingFederate 我有一个使用 Spring Security 进行身份验证的
  • 如何从 firebase 函数访问 firestore

    我已经启动了一个无服务器 Web 应用程序的 Firebase 项目 我可以从客户端访问 Firestore 数据库 从无服务器端 我编写了一个在 http 请求上调用的函数 该函数尝试通过 Firestore 对象访问数据库 但它失败了
  • tr 元素周围的边框不显示?

    Chrome Firefox 似乎不渲染边框tr 但如果选择器是 它会渲染边框table tr td 如何在 tr 上设置边框 我的尝试 不起作用 table tr border 1px solid black table tbody tr
  • 在线性布局内的 ScrollView 内并排对齐 TextView

    我有一个带有滚动视图的线性布局 我想保留它的当前格式 但只需将 textView2a 和 textView3a 并排放置 而不会破坏我当前的布局格式 我已经包含了我最近的尝试 但它们似乎不正确 提前致谢 Java菜鸟 当前有效的 XML