簡體   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