2014-09-19 123 views
0

下面的另一個佈局,這是我的帖子形狀XML fiile膨脹android系統

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/layout_bg" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:layout_margin="10dp" 
    android:id="@+id/hiddenLayout"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/rsz_page_pic" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:id="@+id/imageView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:id="@+id/pageNameTV" 
     android:layout_toStartOf="@+id/imageView" 
     android:paddingRight="10dp" 
     android:layout_alignTop="@+id/imageView" 
     android:layout_toLeftOf="@+id/imageView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="asdasdsd" 
     android:id="@+id/postTimeTV" 
     android:paddingRight="10dp" 
     android:textColor="@color/normal_end" 
     android:layout_alignBottom="@+id/imageView" 
     android:layout_alignRight="@+id/pageNameTV" 
     android:layout_alignEnd="@+id/pageNameTV" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:id="@+id/textView3" 
     android:layout_marginTop="10dp" 
     android:layout_below="@+id/imageView" 
     android:layout_alignRight="@+id/imageView" 
     android:layout_alignEnd="@+id/imageView" /> 

</RelativeLayout> 

我的飼料片段

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingLeft="23dp" 
    android:paddingRight="13dp" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin"> 

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

    </RelativeLayout> 

</ScrollView> 

我的代碼是

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) 
    { 
     mRootView = inflater.inflate(R.layout.fragment_feed, container, false); 

     RelativeLayout hiddenLayout = (RelativeLayout)getActivity().findViewById(R.id.hiddenLayout); 

     RelativeLayout myLayout = (RelativeLayout)mRootView.findViewById(R.id.feeds_container); 
     View hiddenInfo = getActivity().getLayoutInflater().inflate(R.layout.post_shape, myLayout, false); 
     myLayout.addView(hiddenInfo); 

     hiddenInfo = getActivity().getLayoutInflater().inflate(R.layout.post_shape, myLayout, false); 
     myLayout.addView(hiddenInfo); 

     return mRootView; 
    } 

什麼,我試圖做的是讓post_shape.xml複製到feed_fragment.xml中,第一個是正確的,但是當我試圖在第一個下面添加另一個時,我得到了這個http://s14.postimg.org/p8sh0yiq9/ant.jpg 我真的爲我的壞英語,我希望你會明白我的問題,如果你看到的圖片

+0

使用的LinearLayout,而不是相對 – santalu 2014-09-19 20:10:31

回答

1

你有2個chocies這裏... 1.Replace RealtiveLayout與LinearLayout中的文件飼料片段(LinearLayout中必須整個屏幕也是這樣,它會將它們插入其中) 2. ScrollView和RelativeLayout的使用使用ListView和Adapter,這在這裏非常有用。

ListView Example

+0

我用ListView和作品非常感謝你 – user3871129 2014-09-19 21:38:48