2013-10-03 7 views
2

한 활동에서 많은 단편의 문제점이 이전에 다뤘지만, 내 위치 문제에 대한 해결책을 찾을 수없는 것 같습니다.하나의 활동에 여러 조각 있음

화면 위쪽에 사용자 정의 ListFragment 가로 스크롤 막대가 필요합니다. 아래에 게시하는 코드는 스크롤 막대를 올려 놓은 다음 ListFragment가이를 덮어 씁니다. 두 FrameLayouts을 갖기 위해 호스팅 FrameLayout을 수정하려고하면 런타임 오류가 발생합니다.

간단히 말해, 어떻게 listFragment를 스크롤 막대 아래에 배치 할 수 있습니까?

public class Scroll_Menu_Fragment extends Fragment { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    return inflater.inflate(R.layout.scrollbar_fragment, container, false); 
} 

@Override 
public void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
} 

} 

이것은 ListFragment 마지막으로

public class GoogleNewsMainFragment extends ListFragment implements LoaderCallbacks<Cursor> { 

private static final String COLUMN_ID = "id"; 
public final static String NEWSFROMSERVICE = "NEWSFROMSERVICE"; 



static ImageView thumbnail; 
static String mSectionSelected; 
private NewsCursor mCursor; 
private ListView lv; 

private NewsCursorAdapter adapter; 


public static final String ID = "id"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setRetainInstance(true); 

    setHasOptionsMenu(true); 

    mSectionSelected = ""; // until they select one 



    getLoaderManager().initLoader(0, null, this); 




} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 



    View v = inflater.inflate(R.layout.fragment_google_news_main, container, false); 

    getActivity().setTitle(R.string.news_list_title); 

    return v; 
} 

그리고

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fragmentContainer" 
    android:baselineAligned="false" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <fragment 
    android:id="@+id/scrollFragment" 
    android:layout_width="fill_parent" 
    android:layout_weight="10" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    class="com.gilchrist.android.googlenews.Scroll_Menu_Fragment" ></fragment> 

    <fragment 
    android:id="@+id/listFragment" 
    android:layout_width="fill_parent" 
    android:layout_weight="90" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    class="com.gilchrist.android.googlenews.GoogleNewsMainFragment" ></fragment> 
    </LinearLayout> 
+0

나는 추측 u뿐만 아니라 더 많은 정보를 XML에서 조각을 추가해야합니다 그냥 특정 챕터에 vogella 예를 봐 –

+0

나는 원래 게시 된 코드를 변경하고 활동 레이아웃에 조각을 넣어 -에 의해 제안 된 위의 의견에있는 누군가. 아이디어는 화면의 상단을 따라 scrollview와 listFragment가 차지하는 화면의 나머지 부분을 가지는 것입니다. 런타임에이 작업을 시도했을 때와 같은 문제. 화면 상단에 스크롤 막대가 나타나고 listfragment가 전체 화면을 차지하고 스크롤바를 덮어 씁니다. 당신은 어떻게 두 조각을 다른 위에 놓는가? – Glenn

답변

1

난 그냥 활동 레이아웃을 업데이트 호스팅 레이아웃은 다음과 같습니다

public class GoogleNewsMainActivity extends FragmentActivity{ 

public static Context c; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    c=this; 

    setContentView(R.layout.activity_fragment); 


    /* FragmentManager fm = getSupportFragmentManager(); 
    Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); 

    if (fragment == null) { 
     Scroll_Menu_Fragment scrollFragment = new Scroll_Menu_Fragment(); 
     fm.beginTransaction() 
      .add(R.id.fragmentContainer, scrollFragment) 
      .commit(); 

     GoogleNewsMainFragment f = new GoogleNewsMainFragment(); 
     fm.beginTransaction() 
      .add(R.id.fragmentContainer, f) 
      .commit(); 

    } */ 
} 
} 

스크롤 막대 조각입니다 . 문제는 내가 사용했던 가중치 때문입니다. 90과 10으로 가면 나는 내가 원하는 것을 정확하게 얻을 수 있습니다. 위 코드는 모두 작동합니다.

관련 문제