我正在使用StateListDrawable和LayerDrawable以编程方式显示按钮。
它工作正常,但在将添加到我的清单文件后,按钮被拉伸并看起来很难看。
这是我的示例代码...
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);我没有改变任何东西,任何人都可以解释它为什么会导致问题,并解决它。
提前致谢。
-venkat papana