Android 如何在listview中固定布局
我正在设置线性布局的布局。我搜索了很多,但没有找到正确的解决方案 下面是layout.xmlAndroid 如何在listview中固定布局,android,listview,Android,Listview,我正在设置线性布局的布局。我搜索了很多,但没有找到正确的解决方案 下面是layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:orientation="vertical" android:id="@+
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="vertical"
android:id="@+id/lin"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/relative"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:minWidth="250dp"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content"
android:background="@drawable/button2">
<TextView
android:textStyle="bold"
android:id="@+id/name"
android:textSize="15dp"
android:padding="2dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/message121"
android:layout_width="wrap_content"
android:padding="2dp"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"/>
</LinearLayout>
我正在将(id=lin)的父布局移到右侧,但代码无法正常工作。请提出一些解决方案。我不明白您到底想做什么。如果您想在中心移动父级。您可以在xml文件上执行此操作。将布局重力添加到中心我想在listview适配器中将id=lin的父级布局移到右侧。基本上是它的聊天布局,我想通过匹配id将用户自己的布局移动到右侧。通过使用布局,它将移动到右侧,但我想从listview适配器将其移动到右侧。我在上面显示了java代码,但它不工作LinearLayout.LayoutParams params=newlinearlayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);参数重量=1.0f;参数重力=重心;lin.setLayoutParams(参数);我使用此代码但不工作
if(idnew.equals(id)){
Toast.makeText(context,"hello",Toast.LENGTH_SHORT).show();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
lin.setLayoutParams(params);
}