java - 嵌套布局奇怪的问题

标签 java android xml android-fragments android-activity

我有这个 xml:

<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="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.gelasoft.answeringball.MainActivity$PlaceholderFragment" >

    <ImageView
        android:id="@+id/sphereIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:src="@drawable/rsz_rsz_mystic" 
        android:contentDescription="@string/magicBallDescr"/>        

    <LinearLayout
    android:id="@+id/table"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >


<EditText
    android:id="@+id/launch_codes"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:hint="@string/textHint"
    android:inputType="text"
   />

    </LinearLayout>


</RelativeLayout>

如您所见,我在 RelativeLayout 中包含了一个 LinearLayout,但我看到的与我尝试做的相去甚远。

现在我的观点是这样的:

enter image description here

我 3 个问题:

  1. 为什么 LinearLayout 显示在球体图标上方?它被声明为 RelativeLayout

  2. 的子项
  3. 如何将球体放置在线性布局 View 上方?

  4. 如何使球体图标居中?我试过了

    android:layout_centerVertical="true" android:layout_alignParentLeft="true"

但是它将图标放置在 View 的中心。我希望它位于顶部。

我知道我在这里遗漏了一小部分,但作为一个 xml 初学者,我无法发现我的错误。

最佳答案

您可以将其与您的字符串值和 img 资源一起使用

<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="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.gelasoft.answeringball.MainActivity$PlaceholderFragment" >

    <ImageView
        android:id="@+id/sphereIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:contentDescription="magicBallDescr"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:id="@+id/table"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/sphereIcon"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/launch_codes"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="textHint"
            android:inputType="text" />
    </LinearLayout>

</RelativeLayout>

关于java - 嵌套布局奇怪的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23313158/

相关文章:

java - 使用流从字符串中删除多个字符串

android - 如何以编程方式在 fragment 中提供后退按钮?

android - Android中相机 Intent 问题的图像

android - 如何在我的 Android APK 中包含来自 JAR 的 Java 资源?

java - 如何触发@Timeout注解?

java - byte[] 到字符串 {100,25,28,-122,-26,94,-3,-26}

r - 从 xml 中提取信息

xml - groovy 创建新的 xml 节点

xml - XMLDocument 内容类对象的 Xpath 错误

java - Eclipse - 查找 Controller 的 Java 问题