0
我想使用一个9补丁可绘制作为布局的背景,我设定为可点击9为一个可点击的视图
我用抽拉用补丁可拉伸实际上是一个选择器XML其中我写像:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/action_item_pressed" />
<item android:drawable="@drawable/action_item" />
</selector>
和我的布局是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:clickable="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:padding="8dp"
android:background="@drawable/action_item_btn">
<ImageView
android:id="@+id/icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/sword_item"
android:scaleType="centerInside"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="35dp"
android:layout_height="5dp"
android:layout_marginTop="2dp"
style="@android:style/Widget.ProgressBar.Horizontal"/>
</LinearLayout>
的问题是,action_item drawable
有显示,按o当action_item_pressed drawable
正显示出在视图中。
有什么想法?
我是否会夸大这个视图,会导致这种情况?顺便说一句:在eclipse图形布局中,它显示了,如果我在应用程序运行时添加视图,它就可以工作。
这里是我夸大这种观点(它从onCreate
方法调用)的方式:
int achievementsNumber = AchievementsManager.ACTIVE_ACHIEVEMENTS_COUNT;
m_achievementsLayout = new LinearLayout(m_context.getApplicationContext());
m_achievementsLayout.setOrientation(LinearLayout.VERTICAL);
m_achievementsLayout.setGravity(Gravity.CENTER);
LayoutInflater inflater = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int i=0; i < achievementsNumber; i++){
inflater.inflate(R.layout.achievement_item, m_achievementsLayout, true);
}
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
addView(m_achievementsLayout, params);
似乎,它应该工作。 – Michael
我知道。我知道9-patch本身不是问题(除非有9个补丁有时可以工作,有时它们不会是 – piojo
而且如果你在他们的位置更改drawables?哪一个出现? –