Android SDK-在listview行中定位元素
出于某种原因,我在使用eclipse和android SDK进行设计时经历了一段痛苦的时光。制作布局非常困难,不像WPF/VisualStudio那么容易 我正在努力实现以下目标:Android SDK-在listview行中定位元素,android,android-layout,Android,Android Layout,出于某种原因,我在使用eclipse和android SDK进行设计时经历了一段痛苦的时光。制作布局非常困难,不像WPF/VisualStudio那么容易 我正在努力实现以下目标: Top: what I have Bottom: what I want to achieve 当前代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com
Top: what I have
Bottom: what I want to achieve
当前代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:textIsSelectable="false"
android:id="@+id/line1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textSize="18sp"
android:layout_weight="1"
android:textStyle="bold"
/>
<TextView
android:textIsSelectable="false"
android:id="@+id/line2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="18sp"
/>
<TextView
android:textIsSelectable="false"
android:id="@+id/line3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:textSize="18sp"
/>
</LinearLayout>
编辑:
我还尝试在水平线性布局中使用垂直线性布局,但这只会产生很多错误
编辑2:
负面评价是怎么回事
编辑3:
已尝试此链接:
将图像替换为文本视图,但日期仅与顶行对齐。。嗯你应该使用相对论:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="false"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
我建议对此使用
RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:textIsSelectable="false"
android:id="@+id/line1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="18sp"
android:layout_weight="1"
android:textStyle="bold"
android:layout_alignParentLeft="true"
/>
<TextView
android:textIsSelectable="false"
android:id="@+id/line2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_below="@_id/line1"
/>
<TextView
android:textIsSelectable="false"
android:id="@+id/line3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentRight="true"
android:textSize="18sp"
/>
</RelativeLayout>
变化:
将前两行的
LinearLayout
更改为RelativeLayout
使用android:layout\u alignParentLeft=“true”
,第二行的android:layout\u lower=“@+id/line1”
。使用android:layout\u alignParentRight=“true”
和android:gravity=“center\u vertical”将日期向右移动
希望这能满足您的需要。那么您的问题是什么呢?在我链接的图片中,如何在垂直居中的同时正确对齐日期。如何使他的布局与他发布的图片的底部相似。这真的那么令人困惑吗?他有没有说过他在blockquote中写的内容与图片有关,而不是xml@user2011736:我建议使用RelativeLayout,LinearLayout不允许这种行为—这非常有效。非常感谢。这给了我一个如何设计某些东西的好主意。我很高兴它能工作。最好使用尽可能少的布局
和视图
,这样屏幕可以画得更快。这样一来,您就拥有了相同数量的文本视图
,但只有一个布局