Application detail screen

I want to create an app screen in my app as this best design pattern I can think of is the default Android app settings screen which is shown in the screenshot enter image description here

now the problem is i dont know how to create a part "................"

between these key-value pairs, this dashed section should be flexible to capture to grow or shrink to fit the text size on both sides

eg.

scenario 1:

Total..........2MB

(10 dots + text)

scenario 2:

Total........200KB

(8 dots and text)

so the points are adjusted to fit the size of the text.

Can someone suggest me how to achieve this, also please, if you know any better way (patterns) to show a couple key-value

in an application script, this is very welcome.

+3


source to share


3 answers


It's pretty simple (dummy layout):

<RelativeLayout>
    <TextView parentLeft="true"/>
    <TextView parentRight="true"/>
    <Textview background="@drawable/one_dot_repeat"
        toRightOf="@id/firstTextView"
        toLeftOf="@id/secondTextView"
        layout_width="match_parent"> <!-- or any other view -->
</RelativeLayout>

      

Edit: 9patch may not be ideal, but you can create xml where you just add a single dot image and set repeat = "true".



Second edit: a better solution might be to add a shape as a background. The form could be something like this (untested):

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <size
        android:width="500"
        android:height="1" />
    <solid
        android:color="@color/black" />
    <stroke
        android:width="1"
        android:color="@color/white"
        android:dashWidth="1"
        android:dashGap="1" />
</shape>

      

I think you need to tweak the values ​​a bit, but it should work.

+2


source


java.util.Formatter to the rescue:

The formatter can left-justify the text for printing, and you can assign a width to it, so it will fill the text with spaces so that it takes up all the required width, then you just need to replace the spaces with periods. Here's an example:

import java.util.*;

public class Test
{
        public static final synchronized strictfp void main(String[] args)
        {
                Map<String, Double> myData = new LinkedHashMap<String, Double>();
                myData.put("Total", 24.0);
                myData.put("App", 24.0);
                myData.put("USB storage app", 0.0);
                myData.put("Data", 0.0);
                myData.put("SD card", 0.0);


                for(Map.Entry myEntry : myData.entrySet())
                {
                        Formatter myFormatter = new Formatter();
                        myFormatter.format("%1$-20s%2$15.2fKB", myEntry.getKey(), myEntry.getValue());
                        System.out.println(myFormatter.toString().replace(' ', '.'));
                }
        }
}

      

The interesting part here is the format string:

%1$-20s

      

Prints the first argument ($ 1), left-justified (-) with a maximum width of 20 characters (20) as a string.



%2$15.2fKB\n

      

Prints the second argument ($ 2) with a maximum width of 15 characters (15) and 2 decimal points (.2) as float (f).

This means that the first value will always be committed to 20 characters and the second value will always be committed to 15 characters. Then all strings will always be 35 characters + KB suffix + floating point decimal point.

The above code outputs the result:

Total.........................24.00KB
App...........................24.00KB
USB.storage.app................0.00KB
Data...........................0.00KB
SD.card........................0.00KB

      

TODO: don't overwrite legal spaces in first column names;)

+2


source


Although I'm not sure, it still occurred to me that we can also achieve this in the following way:

You determine the total length of the line that you are going to print / display on the screen.

Suppose you have defined it 20. Now you have two cases, let me tell u with an example.

Str1 = Total

Str2 = 200KB

now you can add another line like

Str3 = ";

for (i = 0; i <(20-str1.length () - str2.length))

str3 + = ".";

Now you have three lines: "Total", "200KB / 20KB" and "Dots / ...", you can print them with one TextV or multiple TextViews.

u might also try to calculate the total length instead of 20. As I mentioned, I'm not sure, so no negative votes please: P

0


source







All Articles