android - Android 中的布局创建

标签 android android-layout

这里我粘贴我的布局文件: 可能这个问题已经被问了很多次了,但请 friend 们帮帮我

<ImageView
    android:id="@+id/productImageId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/products_category" />

<RelativeLayout
    android:id="@+id/linearView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/productType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/productName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/productRating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

现在我想要的是图像应该在左边,文本在右边。 图片1名称 图片1类型 图片 1 评分

图像 1 是单个图像,如上面所示,但我的文本以单行形式显示在图像下方,例如

图片1 名称类型评级

谁能告诉我我缺少什么或者我应该在哪里更正我的布局文件。感谢您的考虑。

最佳答案

你的父级可能是一个垂直方向的LinearLayout,尝试在你的代码中添加这个LinearLayout,如下所示:

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
   <ImageView
       android:id="@+id/productImageId"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:contentDescription="@string/products_category" />

   <LinearLayout android:id="@+id/linearView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

       <TextView
           android:id="@+id/productType"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:textAppearance="?android:attr/textAppearanceLarge" />

       <TextView
           android:id="@+id/productName"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:textAppearance="?android:attr/textAppearanceLarge" />

       <TextView
           android:id="@+id/productRating"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:textAppearance="?android:attr/textAppearanceLarge" />
   </LinearLayout>
</LinearLayout>

关于android - Android 中的布局创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20797890/

相关文章:

android - 如何给 fragment 一个对话框的外观?

android - 使用 4 个可调整大小的按钮制作布局

android - 尝试将 fragment 添加到我的 fragment 容器 FrameLayout

Android:主动订阅的 Markdown 是否需要用户同意?

android - Google direction API 给出了错误的距离和持续时间

android - 将原生 Android 转换为 HTML5

android - 更改 Android SeekBar 以在主要进度之上绘制次要进度?

android - 停止线性布局重叠

android - 如何使用 SharedPreferences 保存变量

android - 在 DrawerLayout 内的 NavigationView 顶部布局图像