android 布局调整

android layout justification

我的布局中有图像视图和文本视图,看起来像这样

如何用文本填充空白 space?我已经使用 android:layout_toRightOf="@+id/movie_image" 获取图像旁边的文本,但是当图像结束时它不会填充空白 space。

我的代码

<RelativeLayout 
            android:id="@+id/upperPart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

    <ImageView
            android:id="@+id/movie_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:src="@drawable/ic_launcher"
            android:scaleType="fitXY"/>


    <TextView
        android:id="@+id/title_movie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_toRightOf="@+id/movie_image"
        android:text="@string/temp_title"
        android:textSize="18dp"
        android:textStyle="bold" />

     <TextView
        android:id="@+id/description_movie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:text="@string/moviedescription"
        android:layout_toRightOf="@+id/movie_image"
        android:layout_below="@+id/title_movie"
        android:textSize="14dp"
         />


     </RelativeLayout>

唯一最好的方法是先编辑文本,然后将图像视图保留在其中。 另一种方式是设置两个编辑文本来填充空白。

您想要的在 android 中还无法实现。我建议您改成 textView 可滚动。

<TextView android:id="@+id/title_movie" .../>

中添加以下属性
android:maxLines = "9"
android:scrollbars = "vertical"

Android 的默认 TextView 不支持 justificatoin.. 和 spanning with image view..

您需要检查下面的示例,您可以在其中找到生成图像和文本所需的内容。

How to layout text to flow around an image

要实现这一点,您可以使用两个文本视图,一个位于 ImageView 的右侧,文本一直延伸到 ImageView 的底部。另一个文本视图将位于图像视图下方,宽度为 match_parent。这不会留下任何space。希望这可以帮助你。

试试这个,

<RelativeLayout
        android:id="@+id/upperPart"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/lin_image"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/movie_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="left"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toRightOf="@+id/lin_image" >

            <TextView
                android:id="@+id/title_movie"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:text="@string/temp_title"
                android:textSize="18dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/description_movie"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title_movie"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:text="@string/moviedescription"
                android:textSize="14dp" />
        </RelativeLayout>
    </RelativeLayout>