2017-06-21 56 views
0

我有一個問題,我真的不知道發生了什麼事。爲什麼Drawable背景在大視圖中消失?

這是以下內容,我有一個drawable.xml作爲一個textview的背景,這是一個listview的元素,我設置它,一切正常,但我有行動,當他們觸摸它擴大(改變可見的數量線),那時就是背景丟失了。它的唯一,之後以背景images.9做,效果不錯

下面是提到的內容和畫面發生在非常大的意見

:d sample

<img src="https://i.stack.imgur.com/0wIaX.jpg" alt="Sample" height="50%" width="50%">

Regards

fondo.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" 
    android:paddingBottom="5dp" 
    android:paddingTop="5dp" 
    android:paddingRight="25dp" 
    android:paddingLeft="25dp"> 
<solid android:color="@color/mailUnReadBack" /> 
<corners 
    android:bottomLeftRadius="15dp" 
    android:bottomRightRadius="15dp" 
    android:topLeftRadius="15dp" 
    android:topRightRadius="15dp" /> 
</shape> 

Activity.java

... 
private void expand(View view) { 
    ((TextView) view).setMaxLines(reduceLines?minVal: Integer.MAX_VALUE); 
} 
... 

myView.java

... 
setBackground(getResources().getDrawable(R.drawable.fondo)); 
... 
+0

的方式是相同的文字 –

+0

我不知道,但也許擴大後重新設置背景是什麼? – thorin86

回答

0

嘗試使用以下

抽拉/ fondo.xml

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

    <padding 
     android:bottom="5dp" 
     android:top="5dp" 
     android:right="25dp" 
     android:left="25dp"> 

    <solid android:color="@color/mailUnReadBack" /> 

    <corners 
     android:radius="15dp" /> 
</shape> 

的Java

Drawable background = ContextCompat.getDrawable(context, R.drawable.fondo); 
ViewCompat.setBackground(yourView, background); 
+1

謝謝,我只是使用XML代碼,其工作很好。 –