Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何动态控制ImageView重力_Android_Android Linearlayout - Fatal编程技术网

Android 如何动态控制ImageView重力

Android 如何动态控制ImageView重力,android,android-linearlayout,Android,Android Linearlayout,我有这样一个列表视图: <?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="@+i

我有这样一个列表视图:

 <?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="wrap_content" >

  <ImageView
    android:id="@+id/MSGimage"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:src="@drawable/abc_ab_bottom_solid_dark_holo" />

    <TextView
        android:id="@+id/MSGname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <TextView
        android:id="@+id/comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:background="@drawable/bubble_yellow"
        android:paddingLeft="10dip"
        android:text="Hello bubbles!"
        android:textColor="@android:color/primary_text_light" />

</LinearLayout>

</LinearLayout>
问题是,默认情况下,ImageView位于视图的左侧,但我希望重力正确时,它会移动到TextView的右侧。您能帮我实现这一点吗?非常感谢

wrapper = (LinearLayout) row.findViewById(R.id.wrapper);


    theMessage = (TextView) row.findViewById(R.id.comment);
    theName = (TextView) row.findViewById(R.id.MSGname);
    theImage = (ImageView)row.findViewById(R.id.MSGimage);

     String Namer= 
 mCursor.getString(mCursor.getColumnIndex(MyDbHelperSinglechat.COL_USERNAME));
           String namer[] = Namer.split("\\@");
           String imagenamer=namer[0];

    theName.setText(imagenamer);

theMessage.setText(mCursor.getString(mCursor.getColumnIndex
(MyDbHelperSinglechat.COL_MESSAG
 E)));

    int isright= 
 Integer.valueOf(mCursor.getString(mCursor.getColumnIndex("isright")));

    theMessage.setBackgroundResource(isright==0 ? R.drawable.bubble_yellow : 
 R.drawable.bubble_green);
    wrapper.setGravity(isright==0 ? Gravity.LEFT : Gravity.RIGHT);
    theName.setGravity(isright==0 ? Gravity.LEFT : Gravity.RIGHT);


    File file= new File("storage/sdcard/LifeMatePrivate/ProfileImage
 /ProfileImage,imagechange_2,"+imagenamer+",.jpg");
    if(file.exists()){
    Picasso.with(mContext).load(new File("storage/sdcard/LifeMatePrivate  
/ProfileImage
/ProfileImage,imagechange_2,"+imagenamer+",.jpg")).resize(100,100
).centerCrop().into(theIma    ge);
    }else{
    Picasso.with(mContext).load(new File("storage/sdcard/LifeMatePrivate 
 /ProfileImage/Default.jpg")).resize(100,100).centerCrop().into(theImage);
    }