2015-06-19 41 views
-3

我想用戶的ImageView像機器人:layout_height = 「0.5dp」 將是錯誤

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="0.4dp" 
    android:background="@color/bottomline" /> 

機器人:layout_height = 「0.4dp是錯誤!

錯誤:可疑大小:這將使視圖不可見,應與layout_weight一起使用。

而且我發現,如果ImageView的是LinearLayout中的第一個視圖,這樣

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/backgroundcolor" 
android:orientation="vertical" > 

<!-- first view error --> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="0.4dp" 
    android:layout_marginTop="10dp" 
    android:background="@color/bottomline" /> 

<!-- second view right --> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="0.4dp" 
    android:layout_marginTop="10dp" 
    android:background="@color/bottomline" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:padding="10dp" 
    android:text="李文" 
    android:textColor="@color/black_text_color" 
    android:textSize="16sp" /> 

如何解決這個問題就會出現錯誤?

+1

你確定你想你觀點寬?它甚至不是像素 – webo80

+3

錯誤清楚地表明。這0.4dp是非常小,你無法看到。添加高度,例如10dp你的錯誤將消失 – Amsheer

+1

錯誤清楚地說明最新的問題在那一行。所以,給出最小的'1dp'爲高度。 – Yugesh

回答

0

如果想要細線,您應該嘗試在px中給出高度。

+0

對於所有設備的px密度不一樣,它可能會在hdpi和xhdpi上有所不同,並且... 因此不是一個解決方案... – kAmol

0

的訣竅是不要使用「WRAP_CONTENT」或「FILL_PARENT」你是權重設置的控制。相反,layout_height設置爲0像素(當垂直佈局內),然後將子控件將每重量得到勻稱值

更改layout_height1DP