Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.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 安卓-如何确定图像的位置_Android_Android Imageview - Fatal编程技术网

Android 安卓-如何确定图像的位置

Android 安卓-如何确定图像的位置,android,android-imageview,Android,Android Imageview,我有一个LinearLayout,它有许多文本字段,在LinearLayout的右侧有一个ImageView。但是,图像的位置永远不会固定,并且会根据TextView字段的内容进行移动。我如何解决这个问题?我试过操纵android:Layou gravity,但这并没有给我一个解决方案。我只希望我的图像停靠在右侧,而不考虑TextViews的内容。这是我的布局文件。任何建议或解决方案都将不胜感激 <?xml version="1.0" encoding="utf-8"?> <L

我有一个
LinearLayout
,它有许多文本字段,在
LinearLayout
的右侧有一个
ImageView
。但是,图像的位置永远不会固定,并且会根据
TextView
字段的内容进行移动。我如何解决这个问题?我试过操纵android:Layou gravity,但这并没有给我一个解决方案。我只希望我的图像停靠在右侧,而不考虑
TextView
s的内容。这是我的布局文件。任何建议或解决方案都将不胜感激

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" 
>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="144dp"
    android:orientation="vertical"
    android:layout_gravity="left"

 >

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/name_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/name"  />

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

     </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/date_of_birth_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/date_of_birth"  />

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

     </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/place_of_birth_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/place_of_birth"  />

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

     </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/height_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/height"  />

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

    </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/blood_type_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="@string/blood_type"  />

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

     </LinearLayout>

 </LinearLayout>

<ImageView
    android:id="@+id/member_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"


/>

</LinearLayout>

在最外层的布局中使用RelativeLayout。您可以将图像设置为显示在右侧,垂直居中

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
      >

      <LinearLayout
           android:layout_width="wrap_content"
           android:layout_height="144dp"
           android:orientation="vertical"

           >

           <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal" >

                <TextView
                     android:id="@+id/name_field"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:text="@string/name"  />

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

           </LinearLayout>

           <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal" >

                <TextView
                     android:id="@+id/date_of_birth_field"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:text="@string/date_of_birth"  />

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

           </LinearLayout>

           <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal" >

                <TextView
                     android:id="@+id/place_of_birth_field"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:text="@string/place_of_birth"  />

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

           </LinearLayout>

           <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal" >

                <TextView
                     android:id="@+id/height_field"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:text="@string/height"  />

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

           </LinearLayout>

           <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal" >

                <TextView
                     android:id="@+id/blood_type_field"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:text="@string/blood_type"  />

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

           </LinearLayout>

      </LinearLayout>

      <ImageView
           android:id="@+id/member_image"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentRight="true"
           android:layout_centerVertical="true"

           />

 </RelativeLayout>


尝试用框架布局替换最外层的线性布局。解释这是否不是预期效果。已解决!非常感谢你。