主要的xml:
    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/navlayout"
        android:id="@+id/scroll"
        android:padding="0dp"> 
         <LinearLayout
            android:id="@+id/horizontallayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:layout_marginLeft="10dp"
            android:orientation="horizontal"
             /> 
 </HorizontalScrollView>
添加布局:
 <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/fblayout1"
                    android:layout_width="300dp"
                    android:layout_height="fill_parent"
                    android:background="@drawable/facebook1_texture"
                    android:orientation="vertical"
                    android:padding="5dp" >
                    <RelativeLayout
                        android:id="@+id/navlayout1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content" >
                        <ImageView
                            android:id="@+id/image"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_centerInParent="true"
                            android:src="@drawable/facebook_small" />
                        <TextView
                            android:id="@+id/textheader1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:text="Facebook"
                            android:textColor="#ffffff"
                            android:textSize="20dp"
                            android:textStyle="bold" />
                        <ImageView
                            android:id="@+id/settings1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_centerInParent="true"
                            android:layout_marginRight="5dp"
                            android:background="@drawable/settins_icon"
                            android:visibility="gone" />
                        <ImageView
                            android:id="@+id/close1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_centerInParent="true"
                            android:layout_marginRight="5dp"
                            android:background="@drawable/cross_icon"
                            android:visibility="gone" />
                    </RelativeLayout>
                    <TextView
                        android:id="@+id/note1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/navlayout1"
                        android:padding="5dp"
                        android:text="My Dashboard needs your permission to access your Facebook account before displaying your feed. Login below to give your permission. You will be sent to Facebook first to confirm this."
                        android:textColor="#ffffff"
                        android:textSize="18dp" />
                    <ListView
                        android:id="@+id/list1"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_below="@+id/navlayout1"
                        android:padding="5dp"
                        android:visibility="gone">
                    </ListView>
                    <RelativeLayout
                        android:id="@+id/centerlayout1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:visibility="gone" >
                        <ImageView
                            android:id="@+id/fbimage1"
                            android:layout_width="100dp"
                            android:layout_height="100dp"
                            android:layout_centerInParent="true" />
                        <TextView
                            android:id="@+id/text1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/fbimage1"
                            android:layout_centerHorizontal="true"
                            android:layout_marginTop="20dp"
                            android:text="Facebook"
                            android:textColor="#ffffff"
                            android:textSize="15dp" />
                    </RelativeLayout>
                    <com.databoard.facebook.LoginButton
                        android:id="@+id/fb1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:background="@drawable/login_btn"
                        android:layout_marginBottom="20dp" />
                    <ImageView
                        android:id="@+id/logout1"
                        android:layout_marginBottom="20dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_centerHorizontal="true"
                        android:background="@drawable/logout_btn"
                        android:padding="10dp"
                        android:visibility="gone" />
                </RelativeLayout>
添加视图的代码:
      view= getLayoutInflater().inflate(R.layout.fblayout, null);
RelativeLayout.LayoutParams llp=new RelativeLayout.LayoutParams(400,LayoutParams.WRAP_CONTENT);
  llp.setMargins(0, 0, 100, 0);
  view.setLayoutParams(llp);
  llTotal.addView(view);
上面的代码我用来向水平滚动视图添加视图,但我没有在添加的视图之间获得空间。
我尝试通过为 Linearlayout 和添加的 xml 提供填充,但它对我不起作用。我不明白为什么 llp.setMargins(0, 0, 100, 0); 
    不适用于我的情况。