簡體   English   中英

Android可繪制背景未在設備上顯示

[英]Android drawable background doesn't show on devices

我想給TextView一個背景。 此背景(classement_background.xml)是位於res / drawable中的可繪制對象。

這是它的代碼:

<?xml version="1.0" encoding="utf-8"?>

    <shape
        android:shape="ring"
        xmlns:android="http://schemas.android.com/apk/res/android" >

        <gradient
            android:startColor="#ff648add"
            android:endColor="#ff3656dd"
            android:type="linear"
        />
    </shape>

在布局文件的渲染窗口中,設置了我的背景。 (Android Studio)

但是由於某種原因,這個可繪制對象不再存在於genymotion仿真器或實際設備上。

我一直在嘗試很多事情(例如確保它不是drawable文件夾中的第一個元素),但是我不知道發生了什么。 有什么想法嗎 ?

這是textview本身的代碼:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="E2"
    android:id="@+id/classement"
    android:layout_below="@+id/firstname"
    android:layout_centerHorizontal="true"
    android:textSize="85dp"
    android:layout_marginTop="15dp"
    android:padding="30dp"
    android:background="@drawable/classement_background"
    android:textColor="@android:color/white"/>`

將android:useLevel =“ false”屬性添加到您的shape標簽中。 在添加之前,我的IDE並未在其預覽窗口中顯示您的形狀。

根據文檔

機器人:useLevel

布爾。 如果將其用作LevelListDrawable,則為“ true”。 通常應為“ false”,否則您的形狀可能不會出現。

嘗試為形狀設置android:thickness。 也許android不提供xml drawables的默認厚度。

也許我會發布一些對我有幫助的東西。 我的背景ID為1920x1920像素,顯示1920x1080,所以不同的大小應該不是問題。

我想您已將背景放在Eclipse IDE中的某個資源“可繪制”文件夾中(例如,在drawable-hdpi中 )。 我也有,在真實設備(Sony Xperia Z2)上我什么也沒看見。

簡短答案:

我必須將我想要的背景圖添加到每個可繪制的文件夾中-drawable-ldpi,drawable-xxhdpi, ...


經過這一奇怪的操作,索尼終於認出了我並支持了我。 :-)

我希望這會對某人有所幫助。

暫無
暫無

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

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