0

我正在尝试在我的布局中构建这种线:

“总………………1000”

我需要根据从网络收到的内容更改“1000”。结果,我必须更改 "........." 的宽度。单词“Total”只是一个最终的 TextView。如何在布局中实现它?当手机变为横向时“.....”(点)必须更长,我不知道如何实现它。

所以我有 3 个部分: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>
4

3 回答 3

1

You need to play around with weight attributes : Try below snippet ,make use of below code and design as per your requirement :

<?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>
于 2012-07-03T11:56:49.457 回答
1

Try this,,

<?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>

Two little problems in my code,

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.
于 2012-07-03T12:02:24.297 回答
0

How about a horizontal LinearLayout with the objects of equal layout_weights? "Total" can be wrap_content width, "......" can be match_parent, and "1000" can be wrap_content. Align "Total" to the left, "1000" to the right, and "....." will fill the rest of the space between the other two. However, this would only work if you do something somewhat ridiculous like make the "...." string 200 dots long. In that way, some of the dots will not appear and will run off screen, but at least you'll see all the dots you need between "Total" and "1000". What do you think?

The only other "more complicated" way I could think of doing this is every time you switch orientation or increase/decrease the number, find the width of the screen in pixels, figure out the width of the word "Total" and the each digit of the number in pixels, subtract that from the width, and divide that by the number of pixels a dot takes up. That number would be the amount of dots to put in the "...." string.

于 2012-07-03T11:47:02.777 回答