Android 按钮周围有文本的布局
有谁能建议我如何实现如下布局:Android 按钮周围有文本的布局,android,android-layout,Android,Android Layout,有谁能建议我如何实现如下布局: 这是围绕一个按钮的多行文本。可能是线性布局 您必须创建两个线性布局 inner layout with horizontal orientation ( which will one textview and one button) outer layout with verticalr orientation which wil have textview with wrap content 类似如下 <LinearLayout xmlns:andro
这是围绕一个按钮的多行文本。可能是线性布局 您必须创建
两个线性布局
inner layout with horizontal orientation ( which will one textview and one button)
outer layout with verticalr orientation which wil have textview with wrap content
类似如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear Cache"/>
</LinearLayout>
<TextView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
您可以使用RelativeLayout,然后使用命令格式化布局
android:layout_above="@+id/mybutton"
android:layout_below="@+id/mybutton"
android:layout_toRightOf="@+id/mybutton"
android:layout_toLeftOf="@+id/mybutton"
在API站点上查看RelativeLayout的更多信息(http://developer.android.com/reference/android/widget/RelativeLayout.html)
因此,只有一个布局包含5个组件(4个文本文件和按钮)
编辑:
这里有一个快速而肮脏的解决方案——但对我来说效果很好
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/my_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="BUTTON"
android:layout_centerInParent="true"
/>
<TextView
android:id="@+id/text_above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/my_button"
android:text="TEXT ABOVE BUTTON"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/text_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/my_button"
android:text="TEXT LEFT OF BUTTON"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/text_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/my_button"
android:text="TEXT RIGHT OF BUTTON"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/text_BELOW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/my_button"
android:text="TEXT BELOW BUTTON"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
这是否意味着他必须将文本拆分为单独的文本视图?这不是一个真正的解决方案,只是一个解决方法。这意味着你必须知道在哪里分割文本,使其看起来自然,这意味着测量它可以容纳多少字符或类似的东西,对吗?我同意@DArkO。这只是一个解决办法。如果文本的内容是动态的,那么需要一个额外的函数来决定在哪里拆分文本。