2012-06-28 3 views
2

내 앱의 Android 지원 라이브러리에서 ViewPager를 구현했는데 어떤 이유로 그것이 보이지 않습니다. 앱 레이아웃은 약간 중첩되어있어 일부 문제가 발생합니다. 나는 그것을 의미있는 코드로 압축하려고 노력할 것이다. 내 레이아웃 인플레이션 코드 :Android 지원 ViewPager가 보이지 않습니다.

LinearLayout ll = (LinearLayout) findViewById(R.id.root); 

View v = getLayoutInflater().inflate(R.layout.project_row, null); 

TextView header = (TextView) v.findViewById(R.id.rowheader); 
header.setText(rowHeader); 

ViewPager projectRow = (ViewPager) v.findViewById(R.id.pager); 
projectRow.setAdapter(new ProjectPagerAdapter(tiles)); 

LinePageIndicator lineIndicator = (LinePageIndicator)v.findViewById(R.id.pagerIndicator); 
lineIndicator.setViewPager(projectRow); 
lineIndicator.setStrokeWidth(7); 
lineIndicator.setLineWidth(50); 
lineIndicator.setSelectedColor(Color.parseColor("#555555")); 
lineIndicator.setUnselectedColor(Color.parseColor("#DCDCDC")); 

ll.addView(v); 

project_row.xml :

LinearLayout ll = (LinearLayout) findViewById(R.id.root); 

View v = getLayoutInflater().inflate(R.layout.pageronlytest, null); 
ViewPager vp = (ViewPager)v.findViewById(R.id.pager); 
vp.setAdapter(new ProjectPagerAdapter(tiles)); 

ll.addView(v); 

pageronlytest.xml :

나는이 인플레이션 코드를 사용하는 경우 ViewPager 자체로 작동

<?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" > 

<TextView 
    android:id="@+id/rowheader" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="@color/SectionHeaderColor" /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="280dp" /> 

<com.viewpagerindicator.LinePageIndicator 
    android:id="@+id/pagerIndicator" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

<?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="280dp" 
    android:orientation="vertical" > 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="280dp" /> 

</LinearLayout> 

답변

4

project_row.xml에서 LinearLayout의 방향을 명시 적으로 선언하지 않으므로 '수평'으로 기본 설정됩니다. 첫 번째 요소 (TextView)는 match_parent/fill_parent 너비를 정의하기 때문에 효과적으로 다른 모든 요소를 ​​오른쪽 및 화면 밖으로 밀어냅니다.

즉, LinearLayoutandroid:orientation="vertical"을 추가하면됩니다.

+0

완벽하게 작동했습니다! 나는 그것을 보지 못했다고 믿을 수 없다. – Logiraptor

+0

훌륭한 통찰력의 남자 ....이 대답에 정말 만족합니다! –

관련 문제