【问题标题】:FrameLayout - adding content to FrameLayout to display properlyFrameLayout - 将内容添加到 FrameLayout 以正确显示
【发布时间】: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


【解决方案1】:

这不是error,而是lint warning。您可以使用 compound drawable 替换 ImageView TextView 而不需要 LinearLayout

您可以使用one of these 属性在TextView 上设置drawable。

android:drawableLeft
android:drawableTop
android:drawableRight
android:drawableBottom

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多