簡體   English   中英

Android:如何正確定位圖像

[英]Android: How to position image correctly

大家好我想知道如何使用java而不是xml在liniearlayout中定位圖像。 我正在創建這樣的圖像:

TextView Streets = new TextView(this);          
Streets.setText("Text");                        
Streets.setPadding(140, 25, 0, 25);
Streets.setCompoundDrawablesWithIntrinsicBounds (R.drawable.bus, 10, 10, 10);
Streets.setTag(i);

正如您所看到的,我正在設置圖像的填充,但我想知道如何將圖像設置為啟動TextView。

要將圖像設置為TextView的左側(開始),您不需要ImageView

您可以使用

textView.setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom);

在您的情況下,您只需要在左側設置drawable。

textView.setCompoundDrawablesWithIntrinsicBounds (R.drawable.bus, 0, 0, 0);

代碼更新后:

您將函數10作為top,right和bottom的參數。 所以函數試圖找到一個id等於10的drawable,它可能不存在。

請改用0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM