Android在布局中的定位
我试图在我的布局中构建这样一条线: “总计……1000” 我需要根据我从网络收到的信息更改“1000”。因此,我必须更改“…”的宽度。单词“Total”只是最后一个文本视图。如何在布局中实现它?当手机转向横向时,“点”必须更长,我不知道如何实现它 所以我有三个部分:TextView“Total”,TextView“…”(点),和TextView“1000”,它可以是从1到无穷大的任意名称。如何实现它们,以便根据屏幕大小显示强制性的“总计”和“1000”以及它们之间的“…” 下面的xml不适用Android在布局中的定位,android,android-layout,Android,Android Layout,我试图在我的布局中构建这样一条线: “总计……1000” 我需要根据我从网络收到的信息更改“1000”。因此,我必须更改“…”的宽度。单词“Total”只是最后一个文本视图。如何在布局中实现它?当手机转向横向时,“点”必须更长,我不知道如何实现它 所以我有三个部分:TextView“Total”,TextView“…”(点),和TextView“1000”,它可以是从1到无穷大的任意名称。如何实现它们,以便根据屏幕大小显示强制性的“总计”和“1000”以及它们之间的“…” 下面的xml不适用 &
<RelativeLayout
android:id="@+id/statistic_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/statistic_separator"
android:orientation="horizontal"
android:padding="15dp">
<TextView android:id="@+id/published_recepies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18dp"
android:layout_alignParentLeft="true"
android:textColor="@color/dark_orange"
android:text="Total"/>
<TextView android:id="@+id/dots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_toRightOf="@+id/published_recepies"
android:textColor="@color/dark_orange"
android:text="@string/dots"/>
<TextView android:id="@+id/published_recepies_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_alignParentRight="true"
android:textColor="@color/dark_orange"
android:text="323"/>
</RelativeLayout>
对于布局权重相等的对象,水平
线性布局如何?“总计”可以是wrap\u内容
width,“…”可以是match\u parent
,“1000”可以是wrap\u内容
。将“Total”向左对齐,“1000”向右对齐,“Total”将填充其他两个之间的剩余空间。然而,只有当你做一些有点可笑的事情,比如让“…”字符串有200个点长时,这才有效。这样,一些点将不会出现,并将从屏幕上消失,但至少您将看到“总计”和“1000”之间所需的所有点。你觉得怎么样
我唯一能想到的另一种“更复杂”的方法是,每次你改变方向或增加/减少数字,找到屏幕的宽度(以像素为单位),计算出单词“Total”的宽度和数字的每个数字(以像素为单位),从宽度中减去,然后除以一个点所占的像素数。该数字将是“…”字符串中的点数。您需要使用权重属性:尝试下面的代码片段,使用下面的代码,并根据您的要求进行设计:
<?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="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffeabc" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffedef" >
</LinearLayout>
</LinearLayout>
试试这个
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@android:color/white"
android:singleLine="true"
android:text="......................................................................................................................................................................"
android:textColor="#000000"
android:textSize="18dip" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/white"
android:text="Total"
android:textColor="#000000"
android:textSize="18dip" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@android:color/white"
android:text="1000"
android:textColor="#000000"
android:textSize="18dip" />
</FrameLayout>
android:LinearLayout中的layout\u alignParentRight=“true”是一个不合理的布局。。。重力呢?可以吗?你说的听起来不错,但我得试试。啊,是的,我道歉;试试水平相对论。如果仍然失败,则3个文本视图各自以各自的线性排列在一个封装的RelativeLayout中应该可以工作。我想我已经完成了你所说的,不幸的是,我无法工作,因为所有的点都可以看到(它们的长线)。为了说得更具体,我编辑了答案。欢迎朋友。。!快乐的编码。。!如果我找到了第二个问题的解决方案,我一定会更新我的答案。谢谢。我感谢你的帮助。
1. You need to write so many dots hardcoded in layout xml file.
2. As sometimes there is a some little portion of dots cuts on both side.