【发布时间】:2014-08-11 16:45:28
【问题描述】:
由于某种原因,当我将fragments 添加到我的主布局时,我正在使用FrameLayout,新的fragment 必须是FrameLayout 才能获得正确的match_parent 高度。
但现在我遇到了布置FrameLayout 内容的问题。它在抱怨,因为我在 FrameLayout 中使用了 LinearLayout。
如何在FrameLayout 中布局内容?
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ivLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="@drawable/lhf"
android:contentDescription="@string/Logo"
android:alpha="0"
android:rotation="0"
android:scaleX="0.0"
android:scaleY="0.0"
android:layout_gravity="top"
android:x="150dp"
android:y="150dp"
/>
<TextView
android:id="@+id/txtWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:textSize="12sp"/>
</LinearLayout>
</FrameLayout>
更新
我收到以下警告
Multiple annotations found at this line:
- This LinearLayout layout or its FrameLayout parent is useless
- This tag and its children can be replaced by one <TextView/> and a compound drawable
【问题讨论】:
-
我不明白你的问题,这里到底有什么问题? (我把它粘贴到 Eclipse 中,没有错误)
-
我已经更新了问题,显示我收到的警告
-
@K3NN3TH : 这不是
error它是lint warning -
@kaushik 所以没什么好担心的?
-
@K3NN3TH : 你可以
optimize你的layout删除那些多余的views
标签: android layout android-linearlayout android-framelayout