Android NoteX Q5: Why do horizontal and vertical lines of the same drawable look different?

a problem phenomenon

You can clearly see the difference between the horizontal line and the vertical line. The height is specified as 1px, and the width of the vertical line is also 1px. The corresponding drawables are all the same:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#EEEEEE" />
    <stroke android:color="#EEEEEE"/>
</shape>

Using shape="line" has the same effect.

Two problem solving

In the end, it was found that it was the reason for the Elevation property of CardView. The vertical line in the above figure exists between the two CardViews, and it can be set to 0dp.

app:cardElevation=“0dp”

Three reasons

It can be found through the log output:

Default cardElevation value = 7.0
After setting cardElevation = 0, the value = 0.0

By default, cardElevation has a value of 7.0. Tracing the source code settings can find the default configuration of the CardView style:

cardview_default_evevation = 2dp , because displayMetrics.density = 3.5 , so it ends up being 7.0. Because this width is wider, it results in a visual difference in color value.

Four summary

The solution to this kind of problem is generally very simple, but what happens is more difficult to locate. In the process of finding the cause, we must first believe that the operation of the system is normal, first eliminate the possibility of extreme situations and start from the source of the data, so as to reduce the interference of unnecessary factors.

Learning and discussing together

Guess you like

Origin blog.csdn.net/ganshenml/article/details/115711230
Recommended