在android中使用线性布局时的图像属性
您好,我正在尝试创建一个简单的 Android 页面,其中文本位于页面顶部,图像位于页面下方。我尝试过使用线性布局和相对布局,但我无法让图像显示在文本下方。图像要么位于文本旁边,要么位于左侧,要么位于屏幕右侧,或者当使用相对布局时,图像占据整个屏幕。
是否有任何图像属性可以实现此目的,如果可能的话,我不想使用已弃用的绝对布局。
这是我正在使用的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gripbckgrnd" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="140dp"
android:layout_height="211dp"
android:src="@drawable/grip1" />
<TextView
android:id="@+id/textView1"
android:layout_width="356dp"
android:layout_height="wrap_content"
android:layout_marginTop="97dp"
android:gravity="center_horizontal"
android:text="@string/griptext"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
提前致谢
Hi Im trying to create a simple android page with text at the top of the page and an image below it. Ive tried using both linear and relative layouts but I just cannot get the image to display below the text. Either the image is next to the text either on the left or off the screen to the right, or when using a relative layout the image takes up the entire screen.
Is there any image properties that will allow to accomplish this, I do not want to use the deprecated absolute layout if possible.
Here is the code that I am working with:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gripbckgrnd" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="140dp"
android:layout_height="211dp"
android:src="@drawable/grip1" />
<TextView
android:id="@+id/textView1"
android:layout_width="356dp"
android:layout_height="wrap_content"
android:layout_marginTop="97dp"
android:gravity="center_horizontal"
android:text="@string/griptext"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当使用
LinearLayout
时,你可以像这样指定方向属性:(默认是水平的,这会导致你的问题)
When using
LinearLayout
, you can specify the orientation-attribute like so:(The default is horizontal, which causes your problems)
如果不需要,我建议您即使在 dp 中也不要指定 UI 组件。由于屏幕的尺寸可能会有微小的变化(例如,一些平板电脑的尺寸为 1280x800,一些平板电脑的尺寸为 1280x720),因此最好使用可以拉伸和稍微倾斜的规范,例如 match_parent、wrap_content 和 layout_weight。下面是使用其中一些属性的示例布局。
另外,您的示例将图像放在顶部。 :-)
I recommend you not specify your UI components even in dp, if you don't need to. Because screens can have minor variations in their dimensions (for example, some tablets are 1280x800 and some are 1280x720), it's better to use specifications that can stretch and give a bit, like match_parent, wrap_content, and layout_weight. Here's a sample layout that uses some of these attributes.
Also, your example puts the image on top. :-)