我有这个 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
,但我看到的与我尝试做的相去甚远。
现在我的观点是这样的:
我 3 个问题:
为什么
LinearLayout
显示在球体图标上方?它被声明为RelativeLayout
的子项
如何将球体放置在线性布局 View 上方?
如何使球体图标居中?我试过了
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/