what is the use of android:fadingEdgeLength attribute meant for. i have seen this attribute for some views and wigdets in android project's xml
It's used for adjusting the length of the fading edge that you see when you scroll. You can see the effects on the edges of the screen in the picture below.
From the android official documentation:
Defines the length of the fading edges.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).
The fadingEdgeLengthmanages the size of fading shown at edges of a View.
For instance, a ScrollView or a ListView.
You can combine threquiresFadingEdge to show it horizontally or vertically or none (the latter, in order not to show any).
Related
My question is not about the number of chars nor the textSize attribute in TextView/EditText.
I have a fixed EditText. And the maxLength is 10. And all the chars must be shown at once.
However, each char has different width and height. For example, l and L. If you drag the mouse over(block selection) the l and then the L. You will notice that they have different width.
So, LLLLLLLLLL and llllllllll has different width.
For instance,
LLLLLLLLLL
llllllllll
(both are 10 letters)
Moreover, different font shows different width.
My question is how to get the actual width of chars in PX so that the string won't hidden in the EditText. Let's say, the width of EditText is 200px. And it's limited to 10 letters. And it will show
LLLL(LLLLLL) // (LLLLL) is not shown because of the EditText's width. But you can see when you move the cursor.
llllllllll
How can you get the width of the chars?
you can use TextPaint and measure letters, but there is an easier way for your case. get familiar with em unit
you can declare this value for EditText/TextView by setEms(intNum) or android:ems="intNum". set also width to wrap_content and your View will have width of intNum widest characters (usually Ms). there are also useful minEms and maxEms attributes
edit: HERE you have more complex explanation
PS. don't declare sizes of your Views with px unit due to different densities, use dp. some units explanation in HERE
I want to use this simple layout for items of list:
Note the right gray area (which I draw red rectangle on its border in below) must be a square:
So I have to approximate the height of layout. It must be simple, but the problem is that the text size of TextViews is set by using sp unit and height of layout must be set by dp unit and I did not found a way for converting dp and sp in .xml file. Also I do not want to create a CustomView or change properties of layout at runtime. All things must be done in .xml file. How I can approximate height of layout?
See the TextSize is different from TextView's width and height.
So Provide fixed width-height to all views in "dp". Fixed Text-Size in "sp" that fits perfectly inside TextView.
P.S. -> test in a few devices/emulators to verify.
Lollipop has all those new functions for the "View" class. What exactly are the differences between them, and why do we need so many functions for them?
I've read the docs, and I want to understand (or better understand) the difference and the need for each of them, so that I would know when to use each of them :
elevation
base z depth of the view
Must be a dimension value, which is a floating point number appended
with a unit such as "14.5sp". Available units are: px (pixels), dp
(density-independent pixels), sp (scaled pixels based on preferred
font size), in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"#[package:]type:name") or theme attribute (in the form
"?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol elevation.
So this is what it starts from?
translationZ
translation in z of the view. This value is added to its elevation.
Must be a dimension value, which is a floating point number appended
with a unit such as "14.5sp". Available units are: px (pixels), dp
(density-independent pixels), sp (scaled pixels based on preferred
font size), in (inches), mm (millimeters).
This may also be a reference to a resource (in the form
"#[package:]type:name") or theme attribute (in the form
"?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol translationZ.
So this is added in addition to the "elevation" ? Why is it needed?
And, the most confusing : setZ
Sets the visual z position of this view, in pixels. This is equivalent
to setting the translationZ property to be the difference between the
x value passed in and the current elevation property.
I don't understand the explanation of this at all. Does this affect the shadow? What is it used for? To handle the case that 2 views have the same total elavation value ? Would Animating this value change the way a view is shown?
I have extended the TextView and added support for borders, the thing is when I am drawing a border I need to put padding on the bordered side, so that the text would move.
I set my widths of borders in pixels, and it draws them accordingly, but on my TF201 tablet when I setPadding on the TextView, out of some reason it multiplies the padding width by 3x in pixels even though the setpadding documentation says it is defined explicitly in pixels.
EDIT:
Even though the answer I have selected is not what was causing my issue, it is a valid answer. The real answer to my question is actually a duplicate from this. Problem was that I have added a value to my padding each time setPadding was called. And it does get called three times on a page that has scrolling to it.
It might be a issue of pixel density. Its true that setpadding docs asks to set the padding in pixels but are you setting it in px, sp or dp ? If you read Supporting Different Densities document it says and I quote:
Different screens have different pixel densities,so the same number of pixels may correspond to different physical sizes on different devices.
So, when you specify spacing between two views, use dp rather than px:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clickme"
android:layout_marginTop="20dp" />
When specifying text size, always use sp:
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
Also, based on your comments:
drawRect unit issues android andDraw Rectangle which change size w.r.t different android screen size question might help.
While the method may only accept pixel values, that sadly doesn't save you from needing to take screen densities into account. Instead, you need to determine your values in terms of DP and then programmatically calculate the pixel equivalents at runtime. Fortunately, there are some built-in methods to help you out. This can be done with the following code:
/// Converts 14 dip into its equivalent px
int dimensionInDp = 14;
Resources r = getResources();
float dimensionInPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dimensionInDp, r.getDisplayMetrics());
Although the result is a float, you can easily cast it to an int for use in your setPadding(...) method.
(Referencing: Converting pixels to dp)
When making the android application layouts we have to define the layout width , what is the meaning of the android:layout_width="wrap_content" ?
Either attribute can be applied to View's (visual control) horizontal or vertical size. It's used to set a View or Layouts size based on either it's contents or the size of it's parent layout rather than explicitly specifying a dimension.
fill_parent
Setting the layout of a widget to fill_parent will force it to expand to take up as much space as is available within the layout element it's been placed in.
Setting a top level layout or control to fill_parent will force it to take up the whole screen.
wrap_content
Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.
see the official docs for more details!
android:layout_width="wrap_content" means that the layout is fixed it expand up to exactly as your content size .If your content is more it expand up to that limit and same as in short content.
Here is an example..
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/btnButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button ABC"/>
</RelativeLayout>
wrap_content Image:
wrap_content means that width is determined by the width of the widgets, respectively not the whole display' width but only how widgets need.
Referring to the official Android documentation:
android:layout_width
Specifies the basic width of the view. This is a required attribute
for any view inside of a containing layout manager. Its value may be a
dimension (such as "12dip") for a constant width or one of the special
constants. May be a dimension value, which is a floating point number
appended with a unit such as "14.5sp". Available units are: px
(pixels), dp (density-independent pixels), sp (scaled pixels based on
preferred font size), in (inches), mm (millimeters). This may also be
a reference to a resource (in the form "#[package:]type:name") or
theme attribute (in the form "?[package:][type:]name") containing a
value of this type. May be one of the following constant values.
fill_parent -1 The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parent -1 The view should be as big as its parent (minus padding). Introduced in API Level 8.
wrap_content -2 The view should be only big enough to enclose its content (plus padding).
android:layout_width="wrap_content"
means that layout width is not determined or fixed, it will take space according to its components.
Suppose in a textField u have only one word then your textField will take space for a word only and then it will take space for two word if you have two word in your textField when you will declare your width as wrap_content.
Same thing is applicable for layout_height also.