Android 如何将动态创建的线性布局与其父布局的右侧对齐?

Android 如何将动态创建的线性布局与其父布局的右侧对齐?,android,layout,dynamic,Android,Layout,Dynamic,我试图将动态创建的线性布局与其父级(ListView)右侧对齐。列表视图的代码为 <LinearLayout android:id="@+id/mychatlinear" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="7" android:orientation="ho

我试图将动态创建的线性布局与其父级(ListView)右侧对齐。列表视图的代码为

<LinearLayout
        android:id="@+id/mychatlinear"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="7"
        android:orientation="horizontal"
        android:padding="5dp" >

        <ListView
            android:id="@+id/chatmainlist"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:divider="@color/ripple_material_dark"
            android:dividerHeight="5dp"
            android:padding="5dp"

            tools:listitem="@layout/chatrecieve" >
        </ListView>
    </LinearLayout>

此布局在列表视图中向左对齐。我想把它对准右边。请提出一些解决办法。感谢在
chatitem.xml中更改
LinearLayout
添加
android:gravity=“right”

arg1 = getLayoutInflater().inflate(R.layout.chatitem, null); 



LinearLayout layout = (LinearLayout) arg1;