こんにちは、私は次のXML持っている:私はやりたい何線形レイアウトでプログラム的に配置位置を移動する
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_margin="10dip"
android:weightSum="1"
android:background="#000"
android:orientation="horizontal">
<TextView
android:id="@+id/textMessage"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight = ".9"
android:layout_gravity="center"
android:layout_margin="5dip"
android:paddingLeft="10dip"
android:background="#FFF"
android:text="TEXT NOT SET"
android:textColor="@android:color/white" />
<ImageView
android:id="@+id/thumbPhoto"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight = ".1"
android:src="@drawable/ic_contact_default"/>
</LinearLayout>
</LinearLayout>
はプログラムで私のTextMessageの左側に私のImageViewの変化の位置を持っていることですが。
これは、ImageViewをTextViewの上に置くことでxmlで行うことができます。しかし、私はプログラム的に同じ結果を達成したいと思います。
私は
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.chat_item, parent, false);
}
wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
// How should i change the position of my ImageView ??
wrapper.setGravity([some_condition] ? Gravity.LEFT : Gravity.RIGHT);
return row;
}
Try LayoutParams。 –