LinearLayout - 如何让文本位于图标的右侧?
对于android来说,我是个新手,只正确地工作了几天,但即使在我完成了所有搜索之后,我还是被难住了,似乎没有人知道如何帮助我。到目前为止我有这个:
http://img263.imageshack.us/i/sellscreen.jpg
如何将文本移动到每个图标旁边而不是下方?希望画廊也不要被移动。这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
</LinearLayout>
</ScrollView>
由于某种原因,我的代码的上半部分似乎没有显示,但这只是线性布局的打开。 我将永远感激任何可以提供帮助的人,我已经绞尽脑汁好几天了,却一无所获。真的会因此感到压力很大。提前致谢!!
Bit of a newbie when it comes to android, only been working on it properly for a few days but even after all the searching I've done im stumped and nobody seems to know how to help me. I have this so far:
http://img263.imageshack.us/i/sellscreen.jpg
How can I move the text to be besides each icon rather than underneath it? Hoping the gallery won't be moved either. Here is the code i have:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="@+id/test_image"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
</LinearLayout>
</ScrollView>
Top half of my code doesn't seem to be showing for some reason but it's just the opening of the linear layout.
I will be forever grateful to anyone that can help, i've been racking my brains for days and getting nowhere. Really getting stressed out by it. Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要将每个 ImageView/TextView 对包装在一个线性布局中。
很明显,你没有问任何了解 android 的人,因为这非常简单。
You need to wrap each ImageView/TextView pair in a linearlayout
It's also pretty clear that you didn't ask anyone who knew android, because this is pretty trivial.
你读过 Android 布局教程吗?开发网站上有很多内容,例如 声明布局、< a href="http://developer.android.com/guide/topics/ui/layout-objects.html" rel="nofollow">常见布局对象,以及 hello 视图 教程。
有多种方法可以实现这一目标,具体取决于您的目标。
它是一个可能需要滚动的未知大小的项目列表吗?使用 ListView。您可以为
ListView
提供自定义布局,并将您的内容并排放置。你有一组有限的东西吗?使用 RelativeLayout。告诉每个
TextView
布局在上面的下方,每个ImageView
布局在其TextView
的右侧。您还可以使用嵌套的 LinearLayouts(一个垂直布局和一堆水平布局)来实现此目的,但这比使用RelativeLayout 效率低。
Have you read through the android layout tutorials? Lots of stuff on the dev site, like declaring layout, common layout objects, and the hello views tutorials.
There are a number of ways to accomplish this, depending on your goals.
Is it a list of items of unknown size that may want to scroll? Use a ListView. You can provide a custom layout to the
ListView
with your things side by side.Do you have a finite set of things? Use a RelativeLayout. Tell each
TextView
to layout below the one above, and eachImageView
to layout to the right of it'sTextView
.You could also accomplish that with nested
LinearLayouts
, one vertical and a bunch of horizontal, but that is less efficient than using aRelativeLayout
.