Android 安卓&x2B;你建议哪种布局?
我正在列出一行,以便在ListView中使用,我需要一些帮助。该行将如下所示: 下面是我到目前为止看到的,突出显示的背景没有显示,文本不会对齐中心(粘在顶部)Android 安卓&x2B;你建议哪种布局?,android,android-layout,Android,Android Layout,我正在列出一行,以便在ListView中使用,我需要一些帮助。该行将如下所示: 下面是我到目前为止看到的,突出显示的背景没有显示,文本不会对齐中心(粘在顶部) 我只会使用一个RelativeLayout。它将避免使用各种布局和布局 在屏幕上放置组件更容易 编辑:此解决方案有效,但我不知道它是否是最好的: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schema
我只会使用一个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="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="0.25"/>
<ImageView
android:layout_weight="0.5"
android:layout_height="0dp"
android:layout_width="50dp"
android:background="#dedede"/>
<View
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="0.25"/>
</LinearLayout>
<!--
...
-->
</RelativeLayout>
查看本教程,您可以选择最佳布局。每种布局都有其优缺点。只有一种布局在android中不是最好的,但在大多数情况下,
相对布局
易于使用,因为它可以轻松移动到UI的任何位置
就像你的比赛问题,教程
您可以在developer.android.con中看到更多的布局。这需要学习更简单的方法。这里有一些最佳链接
,您可以看到各种布局
看看这个
![<?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="35dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="4"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Row 1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Row 2" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Row 3" />
</LinearLayout>
</LinearLayout>
<View android:layout_height="match_parent"
android:layout_width="2dp"
android:background="#fff"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
</LinearLayout>
![
感谢链接!为了更具体,使用线性布局是将两个视图设置为50%高度(或宽度)的唯一方法吗?是的,但是如果将背景高光设置为50%的高度,我是否仍然需要使用线性布局来实现这一点?如果是这样,这不需要像我上面所做的那样,使用框架布局将其放置在任何相对位置的后面吗?嗯..您只需要在ImageView中使用50%的高度?此外,您可以将视图垂直对齐到同一视图中的另一个视图吗parent RelativeLayout?我需要这样的属性,android:layout_alignvertical=“@id/view”是的,我们需要一个线性布局。请看上面谢谢你的帖子!有趣的是,我可以在eclipse预览窗口中看到光芒,只是在它为手机或模拟器编译时看不到。长话短说,我坚持我所拥有的,并使用形状渐变作为背景绘制。
![<?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="35dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="4"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Row 1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Row 2" />
<TextView
android:layout_marginLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Row 3" />
</LinearLayout>
</LinearLayout>
<View android:layout_height="match_parent"
android:layout_width="2dp"
android:background="#fff"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
</LinearLayout>