Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

android - Why would Eclipse tell me there is no attribute "margin" for a LinearLayout?

I'm getting an error when I try and build my android project:

No resource identifier found for attribute 'margin' in package 'android'

And it references this layout as the culprit. But I can't find anything wrong with it.

Any idea why Eclipse would think there is not margin on these views that do have margins ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:background="@color/feedstory_background_color"
    android:margin="5dp"
    android:orientation="vertical"
    android:padding="5dp" >

    <RelativeLayout
        android:id="@+id/feed_profile_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp" >

        <ImageButton
            android:id="@+id/feed_profileImage"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_alignParentLeft="true"
            android:layout_margin="0dp"
            android:background="@color/black_bg"
            android:maxHeight="60dp"
            android:maxWidth="60dp"
            android:padding="1dp"
            android:scaleType="centerInside"
            android:src="@drawable/feed_blank_profile_picture" />

        <LinearLayout
            android:id="@+id/profile_texts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/feed_profileImage"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/profile_name_text"
                style="@style/feed_profile_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/feed_profile_name" >
            </TextView>

            <TextView
                android:id="@+id/profile_location_text"
                style="@style/feed_profile_location"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/feed_profile_location" >
            </TextView>

            <TextView
                android:id="@+id/profile_time_text"
                style="@style/feed_profile_time"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/feed_profile_time" >
            </TextView>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/profile_texts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:orientation="vertical" >

            <Button
                android:id="@+id/fan_button"
                style="@style/feed_button_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:background="@drawable/red_button"
                android:margin="0dp"
                android:minHeight="0dip"
                android:minWidth="70dip"
                android:padding="5dp"
                android:text="@string/feed_fan_button" />

            <TextView
                android:id="@+id/fan_count_text"
                style="@style/feed_button_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/grey_button"
                android:margin="0dp"
                android:minHeight="0dip"
                android:minWidth="70dip"
                android:padding="5dp"
                android:text="000000" >
            </TextView>
        </LinearLayout>
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/content_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/post_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/feed_default_post_text"
            style="@style/feed_text_style"
            >


        </TextView>

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/feedback_buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/applaud_button"
            style="@style/feed_button_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="2dp"
            android:background="@drawable/red_button"
            android:minHeight="0dip"
            android:minWidth="70dip"
            android:text="@string/feed_applaud_button" />

        <TextView
            android:id="@+id/applaud_count_text"
            style="@style/feed_button_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="2dp"
            android:layout_toRightOf="@id/applaud_button"
            android:background="@drawable/grey_button"
            android:margin="10dp"
            android:padding="10dp"
            android:text="000000" >

        </TextView>

        <Button
            android:id="@+id/comment_button"
            style="@style/feed_button_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginRight="2dp"
            android:layout_toLeftOf="@+id/comment_count_text"
            android:background="@drawable/red_button"
            android:minHeight="0dip"
            android:text="@string/feed_comment_button" />

        <TextView
            android:id="@+id/comment_count_text"
            style="@style/feed_button_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="0dp"
            android:layout_weight="1"
            android:background="@drawable/grey_button"
            android:text="000000" >

        </TextView>
    </RelativeLayout>

</LinearLayout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The correct attribute name for declaring a 5p margin in every direction is:

android:layout_margin="5dp"

Note the layout_ prefix. You'll want to remove the line that says android:margin="5dp", which is what makes Eclipse complain.

The full set of valid margin attributes includes:

  • layout_margin
  • layout_marginBottom
  • layout_marginEnd
  • layout_marginLeft
  • layout_marginRight
  • layout_marginStart
  • layout_marginTop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...