繁体   English   中英

Android中的Android定位

[英]Android positioning in Layout

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

“总...................... 1000”

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

所以我有3个部分:TextView“Total”,TextView“......”(点)和TextView“1000”,可以是从1到无穷大的任何namber。 如何实现它们以根据屏幕大小显示强制性“总计”和“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>

您需要使用权重属性:尝试以下代码段,根据您的要求使用以下代码和设计:

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

我的代码中有两个小问题,

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.

具有相同layout_weights的对象的水平LinearLayout怎么样? “total”可以是wrap_content width,“......”可以是match_parent ,“1000”可以是wrap_content 将“Total”对齐到左边,“1000”对齐,“.....”将填充其他两个之间的空间。 但是,这只有在你做一些有点荒谬的事情时才会起作用,例如将“......”字符串设置为200点长。 这样,一些点将不会出现并将在屏幕外运行,但至少你会看到“Total”和“1000”之间所需的所有点。 你怎么看?

我能想到的唯一其他“更复杂”的方法是每次切换方向或增加/减少数字,找到屏幕宽度(以像素为单位),找出单词“Total”的宽度和每个数字以像素为单位的数字,从宽度中减去该数字,并将其除以点占据的像素数。 该数字将是放在“....”字符串中的点数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM