【发布时间】:2014-09-18 23:41:15
【问题描述】:
我想要一个图像来定义布局的边界,并且需要所有其他元素来定位它们自己。
我的问题是我希望文本在到达图像末尾时换行。知道如何通过布局 xml 解决这个问题,还是我必须通过代码来实现?
我当前的布局是这样的:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/KHFGreen"
android:padding="3dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_gravity="left|center_vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/five"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore. "
android:layout_gravity="left|center_vertical"
android:nestedScrollingEnabled="false" />
</FrameLayout>
</FrameLayout>
非常感谢!
【问题讨论】:
-
对图像视图使用 matchparent,对文本使用 android:ellipsize="end"
-
感谢您的回答,但不幸的是,这并没有改变任何事情:/
-
我可以看到你只想要你的布局的边框然后你使用图像来做同样的事情?
-
是的,这个布局将在 ListViewAdapter 中膨胀。我想要一个带有绿色边框的图像,并且该图像顶部有一个文本。但是文本到达图像末尾时应该换行......
-
我不确定仅使用 xml 布局是否可行。我认为您需要以编程方式解决此问题。
标签: android xml android-layout android-inflate android-adapterview