开发者

Android: android:minSdkVersion=8 causing problem to my button views

开发者 https://www.devze.com 2023-03-29 20:26 出处:网络
I\'m using StateListDrawable and LayerDrawable for displaying buttons programatically. It is working fine,bu开发者_开发百科t after adding <uses-sdk android:minSdkVersion=\"8\" /> to my manifest

I'm using StateListDrawable and LayerDrawable for displaying buttons programatically. It is working fine, bu开发者_开发百科t after adding <uses-sdk android:minSdkVersion="8" /> to my manifest file, the buttons are stretched and looking ugly.

Here is my sample code...

Drawable btnNormal = context.getResources().getDrawable(R.drawable.button1);
Drawable btnPrssed = context.getResources().getDrawable(R.drawable.button2); 

Drawable cnLogo = context.getResources().getDrawable(R.drawable.logo);
Drawable rightArrow = context.getResources().getDrawable(R.drawable.arrow);

Drawable[] cnDrawablesNormal = new Drawable[]{btnNormal, cnLogo, rightArrow};
LayerDrawable cnLayersNormal = new LayerDrawable(cnDrawablesNormal);
cnLayersNormal.setLayerInset(1, 10, 1, 250, 1);
cnLayersNormal.setLayerInset(2, 280, 17, 20, 17);  

Drawable[] cnDrawablesPressed = new Drawable[]{btnPrssed, cnLogo, rightArrow};
LayerDrawable cnLayersPressed = new LayerDrawable(cnDrawablesPressed);          
cnLayersPressed.setLayerInset(1, 10, 1, 250, 1);
cnLayersPressed.setLayerInset(2, 280, 17, 20, 17);  

states.addState(new int[] {android.R.attr.state_pressed},cnLayersPressed);
states.addState(new int[] { }, cnLayersNormal); 

I didnt change anything, can anybody explain why it is causing prob, and fix for it.

Thanks in advance.

-venkat papana


I have had a similar problem, I solved it by adding the android:targetSdkVersion value in the AndroidManifest so it will look something like this

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号