私は Android アプリケーションで作業しています。私のアプリでは、テキストビューの配置を動的に変更しました。テキストビューは相対レイアウトです。以下は私のサンプルxmlファイルです
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/all"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
>
<TextView android:id="@+id/snt_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/Gold"
android:text="df"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:padding="3dp"/>
</RelativeLayout>
そしてJavaで私は次のことをしました
View vi = inflater.inflate(R.layout.smsconversationsent_row, null);
RelativeLayout nws=(RelativeLayout)vi.findViewById(R.id.all);
TextView message=(TextView)vi.findViewById(R.id.snd_txt);
RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)message.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
message.setLayoutParams(params);
しかし、message.getlayoutparams() で nullpointer 例外が発生しています。