-2
Я использую LayoutInflater для создания динамически ui с xml-файлами, но resualt не подходит. как надуватель не установлен макет параметров? мой пример кода:Do'nt set LayoutParams LayoutInflater
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.linearlayoutdef, null);
ImageView iv = (ImageView) inflater.inflate(R.layout.imageviewdef, null);
iv.setImageBitmap(op.getImage());
TextView tv = (TextView) inflater.inflate(R.layout.textviewdef, null);
//tv.setText(op.getType().toString());
tv.setText("Call");
Button be = (Button) inflater.inflate(R.layout.buttondef, null);
be.setText("Edit");
Button bd = (Button) inflater.inflate(R.layout.buttondef, null);
bd.setText("Delete");
ll.addView(iv);
ll.addView(tv);
ll.addView(be);
ll.addView(bd);
мой образец XML-файлы:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/linearLayout" >
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="linearLayout" >
<item name="android:orientation">horizontal</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">40pt</item>
<item name="android:background">@color/white</item>
<item name="android:layout_marginLeft">3pt</item>
<item name="android:layout_marginRight">3pt</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/imageViewStyle" android:contentDescription="@string/todo"
android:src="@drawable/stop"
>
</ImageView>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="imageViewStyle" parent="@android:style/Widget">
<item name="android:layout_width">30pt</item>
<item name="android:layout_height">30pt</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_marginLeft">3pt</item>
<item name="android:background">@drawable/imageview_background</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape android:shape="rectangle" >
<stroke android:width="0.9pt" android:color="#808080"/>
</shape>
</item>
</layer-list>
результат ведьма:
но правый результат должен быть:
что я могу сделать, чтобы получить правильный результат?
почему бы вам не сделать все виджеты в одном макете. –