首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android图像和文本

Android图像和文本
EN

Stack Overflow用户
提问于 2015-11-16 20:48:18
回答 3查看 65关注 0票数 0

我正在开发一个安卓应用程序。我希望屏幕上的图像和下面的是image.After的名字下面的图像,即在下半部分应该有一些描述在5-6 lines.Getting的图像在上半部分,但不能在下半部分的文字。

向Mayank致敬

EN

回答 3

Stack Overflow用户

发布于 2015-11-16 20:57:22

如果我是您,我会使用带有weightSum字段的LinearLayout和LinearLayout中每个元素的layout_weight。例如:

代码语言:javascript
运行
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16p"
    android:weightSum=5>

<ImageView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight = 3/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/> </LinearLayout>

在上面的示例中,我们有一个屏幕,它垂直地包含一个ImageView (屏幕的3/5)和两个TextViews (每个屏幕的1/5)。

票数 1
EN

Stack Overflow用户

发布于 2015-11-16 20:57:24

只需要复制这个

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4"
            android:id="@+id/imageView2"
            android:layout_gravity="center_horizontal" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/textView2"
            android:gravity="center"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/textView3"
            android:gravity="center"
            android:layout_gravity="center_horizontal"
            android:layout_weight="2" />
    </LinearLayout>
票数 0
EN

Stack Overflow用户

发布于 2015-11-16 21:07:03

尝尝这个,

代码语言:javascript
运行
复制
<?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="match_parent"
    android:background="@android:color/background_light"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.5"
            android:orientation="vertical"
            android:weightSum="5" >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="4"
                android:background="@drawable/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:text="Hello World"
                android:paddingBottom="5dp"
                android:textSize="25sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.5"
            android:orientation="horizontal"
            android:background="#336699">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="bottom|center"
                android:layout_gravity="bottom|center"
                android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
                android:textSize="20sp"
                android:textColor="@android:color/white" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

输出如下所示:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33735802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档