2013-06-05 2 views
0

두 개의 XML 파일이 있습니다. 그 중 하나에는 ListView와 listView를 채우는 사람이 있습니다. 나는 항목을 표시 할 수 있지만 것은 스크롤 할 수 없습니다. 예를 들어 표시 할 항목 목록이 있지만 스크롤을 자동으로 활성화하지는 않습니다. 스크롤 할 수 있도록 코드의 어느 부분을 향상시켜야합니다. ListView를 사용하면 기본적으로 스크롤 할 수 있습니다. 이걸로 나를 도와주세요. 미리 감사드립니다.ListView를 스크롤 가능하게하기

public class ActivityViewCategory extends ListActivity { 

       @Override 
       public void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.activity_view_products); 

       // Hashmap for ListView 
       productsList = new ArrayList<HashMap<String, String>>(); 
       // Get listview 
       ListView lv = getListView(); 
          . 
          . 
          . 
    protected void onPostExecute(String file_url) { 
       // dismiss the dialog after getting all products 
       pDialog.dismiss(); 
       // updating UI from Background Thread 
       runOnUiThread(new Runnable() { 
        public void run() { 
         /** 
         * Updating parsed JSON data into ListView 
         ArrayList<HashMap<String, String>> com.example.restotrial.ActivityViewCategory.productsList * */ 

         ListAdapter adapter = new SimpleAdapter(
           ActivityViewCategory.this, productsList, 
           R.layout.list_item, new String[] { TAG_PID, 
             TAG_NAME}, 
           new int[] { R.id.pid, R.id.name }); 
         // updating listview 
         setListAdapter(adapter); 
        } 
       }); 
      } 
     } 

activity_view_products.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <!-- Main ListView 
     Always give id value as list(@android:id/list) 
    --> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="456dp" > 
    </ListView> 


</LinearLayout> 

list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 


    <!-- Product id (pid) - will be HIDDEN - used to pass to other activity --> 
    <TextView 
     android:id="@+id/pid" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:visibility="gone" /> 


    <!-- Name Label --> 
    <TextView 
     android:id="@+id/name" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="6dip" 
     android:paddingLeft="6dip" 
     android:textSize="17dip" 
     android:textStyle="bold" /> 


</LinearLayout> 
+1

이 답변을 확인하십시오 : http://stackoverflow.com/questions/4310738/making-android-listview-layout-scrollable – verybadalloc

+0

질문을 수정하여 시도한 다른 답변을 포함시킬 수 있습니까? 그것은 내가 당신의 문제에 대한 해결책을 찾는 나의 범위를 줄이는데 도움이 될 것입니다. – verybadalloc

답변

1

나는 당신이 당신의 ListView를 포함하는 RelativeLayout의의 제약을 사용하는 경우는 잘 작동 할 것이라는 점을 생각한다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
    <!-- Main ListView 
     Always give id value as list(@android:id/list) 
    --> 

    <ListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 
      android:layout_height="wrap_content" > 
    </ListView> 


</RelativeLayout> 

당신의 ListView의 시각적 최고 상위 뷰의 상단에있을 것, 시각적 바닥이 상위 뷰의 맨 아래에있을 것입니다, 당신의 목록이 될 일이 같은 콘텐츠를 한 것, 필요에 따라 스크롤하십시오.

+1

ListView가 이제 HalR 덕분에 스크롤됩니다. 직접적이고 명확한 대답에 감사드립니다. 환호! ~ – rahstame

관련 문제