我有一个左对齐的 TextView 和一个并排的右对齐按钮。我希望按钮在右侧占用尽可能多的空间(取决于其中的文本),左侧文本尽可能多地填充,并在任何溢出时省略。
|Long title that may or may not ellipsi... <Button with text>|
我已经阅读并尝试了很多其他似乎有类似问题的帖子,但没有一个对我有用。我尝试过使用带权重的 LinearLayout 以及分配了 layout_toLeftOf 的 RelativeLayout,但都没有满足我的需要。
这是我的 LinearLayout 代码(去掉了不必要的部分),我给左边的 TextView 一个 layout_weight 为 1,按钮的 layout_weight 为 0。这应该给右边的按钮所有它需要的空间,并给 TextView其余的,而是左边的标题停止显示,右边的按钮被弄脏到一边并被切断。我已经尝试将文本和按钮的宽度都替换为 0dip,正如我所看到的那样,这不会改变任何东西。
<LinearLayout
android:layout_height="@dimen/title_bar_height"
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:layout_gravity="left|center_vertical"
android:gravity="left|center_vertical"
android:textSize="22sp"
android:lines="1"/>
<include layout="@layout/action_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
将 TextView 的 layout_weight 替换为 0 实际上可以使右侧按钮完全适合屏幕,但左侧文本仍然不显示。如果我将 TextView 和按钮的 layout_weights 都设置为 0,然后将 TextView 的宽度从 0dip 更改为 wrap_content,则一切都会显示,但按钮会被挤压以填充剩余空间(并且内部文本被截断)。
这是我对 RelativeLayout 的尝试:
<RelativeLayout
android:layout_height="@dimen/title_bar_height"
android:layout_width="wrap_content">
<include layout="@layout/action_buttons"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@layout/action_buttons"
android:gravity="center_vertical"
android:scaleType="center"
android:textSize="22sp"
android:ellipsize="end"
android:lines="1"/>
</RelativeLayout>
一切都很好地对齐并显示出来,除了左侧的 TextView(当它太长时)重叠并出现在按钮的顶部而不是截断和省略。 android:layout_toLeftOf"@layout/action_buttons"不应该指定 TextView 应该保持在按钮的左边界吗?
我已经尝试了似乎在该站点上可以找到的与此问题相关的所有内容,但我仍然无法找到解决方案。任何帮助将不胜感激!
最佳答案
这将为您解决问题:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="Some really long textttttttttt tooooooooooo make the ellipsize work in the preview"
android:textSize="22sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Text" />
</LinearLayout>
这是运行时的样子:
还有一个带有更多文本的按钮:
关于Android TextView 和 Button 并排,椭圆形左侧 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10822096/
我正在尝试使用button_torails助手。我写了下面的代码:'mark-button'%>得到如下错误信息Noroutematches"/items/1/edit"但是当我刷新页面时,它会执行适当的操作。我得到的页面的URL是localhost:3000/items/1/edit这是正确的网址。如果我切换button_to命令link_to页面加载没有错误。意思是这段代码:'mark-button'%>加载正常。也许有一些特点button_to我不知道,但我迷路了。 最佳答案 我认为您可能误用了button_to。我一直认为,
在我的routes.rb文件中,我想使用rails3中的子域约束功能,但是我想从catchall路由中排除某些域。我不想在特定的子域中有特定的Controller。这样做的最佳做法是什么。#thissubdomainidontwantallofthecatchallroutesconstraints:subdomain=>"signup"doresources:usersend#hereIwanttocatchallbutexcludethe"signup"subdomainconstraints:subdomain=>/.+/doresources:carsresources:sta
我正在尝试将温度从华氏度转换为摄氏度:puts'ConvertirgradosFahrenheitaCelcius'STDOUT.flushx=gets.chompaprox=(x*100.0).round(2)/100.0resultado=(aprox-32)/1.8putsresultado我使用正确的公式将华氏度转换为摄氏度:Celsius=Fahrenheit-32/1.8但是,当我在控制台中运行它时,出现以下错误:`round':wrongnumberofarguments(1for0)(ArgumentError)我尝试过不同的方法,但我不明白为什么这不起作用。
我正在尝试编写Ruby代码来检查我发现的特定消息上的椭圆曲线数字签名算法(ECDSA)签名here.问题是我不知道如何将公钥的八位字节字符串转换为OpenSSL::PKey::EC::Point目的。如果我用C写这个,我会把八位字节字符串传递给OpenSSL的o2i_ECPublicKey,它做的事情接近我想要的,实际上被referenceimplementation使用.但是,我搜索了sourcecodeofRuby(MRI)而且它不包含对o2i_ECPublicKey的调用,所以我不知道如何在不编写C扩展的情况下使用Ruby中的该函数。这是十六进制的八位字节字符串。它只是一个0x0
我有一个使用form_tag助手的基本表单,但我想添加一个取消按钮,这样做的语法是什么?我希望取消按钮显示为按钮而不是链接,然后将用户带到不同的URL(表明他们不想提交表单)。泰,弗雷德 最佳答案 如果您想清除/重置表单字段,请按照weltschmerz的建议进行操作。但是,我通常希望“取消”按钮不会清除表单,而是让我离开表单,这意味着我不打算提交它。如果你想要后者,我会在取消时创建一个链接(或按钮)到你想去的页面,例如:=link_to'Cancel',my_page_path或者如果你想要一个按钮:=button_tag"Can
需要提前知道的一些东西Android中获取View的宽度或者高度,可以通过View自带的方法getWidth()、getHeight(),但这仅限于layout_width和layout_height的值是具体的dp或者match_parent,如果值是wrap_content,那么直接调用getWidth()、getHeight()方法,可能返回的会是0。直接调用getWidth()、getHeight()可能返回0的原因是,View可能还没有被添加到界面上(这里添加到界面上是指View执行了onMeasure方法),View添加到界面上之后,才计算完宽度和高度,所以如果宽度或高度如果设置w
先给大家看看最终效果首先我们来定义数据data(){ return{ lsit:[ 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic118.nipic.com%2Ffile%2F20161216%2F24271963_122609717000_2.jpg&refer=http%3A%2F%2Fpic118.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656923017&t=183ece148b13b64e9dd503afd1b15c91'
在此先感谢任何尝试帮助我的人。我有一个表单,我根据一系列条件通过appendChild()将复选框添加到-作为供用户选择的选项。当用户选中这些框中的任何一个,然后单击“继续”按钮以将选择发布到另一页时,然后单击后退按钮-用户选中的复选框,现在被忘了,浏览器(不再选中)。如果我使用php编写复选框,或者仅使用静态复选框-当用户选中其中任何一个复选框,然后单击“继续”按钮以将选择发布到另一页时,然后单击“后退”按钮-选定的复选框被记住了(仍处于选中状态)我的问题是:当我使用appendChild()创建复选框时,浏览器为什么会忘记用户所做的选择但是同一浏览器会记住,当用户使用静态复选框时所
我发现很多时候页面都使用“a”标签,并想把它做成一个按钮。是这样的:我很困惑为什么不只使用“按钮”标签?像这样:button有什么区别?很想学,谢谢!还有一个情况问题:三个“类似按钮的标签”如下:提示:不同的一次调用ajax得到不同的时期记录需要使用onclick="location.replace()"才能顺利回到上一页。原代码:Today我已更改为:Today考虑:Today在这种情况下你会怎么做?使用按钮标签有什么不正确的地方吗? 最佳答案 这基本上是一件历史文物。它源于将自定义样式应用于anchor要容易得多的时代。通过在a
我刚开始学习Angular,但遇到以下错误:无法绑定(bind)到“已禁用”,因为它不是的已知属性.在互联网上搜索我只是发现了类似的错误,但它们与未导入FormsModule这一事实有关,这似乎不是我的情况。app.components.tsimport{Component}from'@angular/core';@Component({selector:'app-root',templateUrl:'./app.component.html',styleUrls:['./app.component.css']})exportclassAppComponent{title='app';