Относительное расположение в представлении прокрутки не работает - PullRequest
1 голос
/ 27 октября 2011

Я пытаюсь поместить вид прокрутки в относительное расположение.Здесь некоторая часть макета в верхней и нижней части должна быть постоянной.Поэтому я использую еще один макет внутри, в котором есть элементы, которые нужно прокрутить.

Но этого не происходит, и экран выглядит очень плохо.Я получаю некоторое черное пространство в нижней части части, где я определил вид прокрутки.

Вот мой xml,

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

<TextView android:id="@+id/textView1" android:layout_below="@+id/logoTop"
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:text="TextView" android:layout_alignLeft="@+id/logoTop"></TextView>

<ImageView android:src="@drawable/logotop" android:id="@+id/logoTop"
    android:layout_alignParentTop="true" android:layout_width="match_parent"  
    android:scaleType="fitXY" android:layout_height="wrap_content"></ImageView>

<ImageView android:src="@drawable/bardown" android:id="@+id/barDown"
    android:layout_width="match_parent" android:scaleType="fitXY"
    android:layout_alignParentBottom="true" android:layout_height="40dip">
</ImageView>

<ImageButton 
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:id="@+id/btnMap" android:layout_centerInParent="true" android:src="@drawable/map"
    android:background="@drawable/mapselector" android:scaleType="fitXY"
    android:layout_alignParentBottom="true">
</ImageButton>

<ImageButton 
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:id="@+id/utBtn" android:background="@drawable/utilitiesicon"
    android:scaleType="fitXY" android:layout_alignTop="@+id/barDown" android:src="@drawable/utilityselector"
    android:layout_alignParentRight="true" android:layout_marginRight="10dip"
    android:layout_marginTop="3dip">
</ImageButton>

 <ScrollView 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_below="@+id/logoTop"
  android:layout_above="@+id/barDown"
  android:scrollbars="none">

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

<ImageView android:id="@+id/abtHome" android:layout_below="@+id/logoTop"
    android:src="@drawable/abouthome" android:scaleType="fitXY"
    android:layout_width="match_parent" android:maxWidth="230dip"
    android:layout_height="230dip">
</ImageView> 

<ListView android:id="@+id/tourList" android:layout_below="@+id/abtHome"
    android:scrollbars="none" android:visibility="visible"
    android:layout_centerInParent="true" android:layout_above="@+id/barDown"
    android:background="#FFFFFF" android:cacheColorHint="#00000000" android:fadingEdge="horizontal"
    android:fastScrollEnabled="true" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:isScrollContainer="false">
</ListView> 

<TextView android:id="@+id/tourcity" android:layout_above="@+id/tourList"
    android:layout_height="wrap_content" android:layout_width="match_parent"
    android:textSize="25dip" android:layout_centerHorizontal="true"
    android:editable="false" android:paddingTop="5dip" android:textColor="@color/white"
    android:paddingBottom="5dip" android:background="#80000000" android:gravity="center"></TextView>

</RelativeLayout>
</ScrollView>

<ImageButton android:src="@drawable/arrowselector"
    android:layout_height="wrap_content" android:layout_width="wrap_content"   android:layout_alignTop="@+id/barDown"
    android:id="@+id/btnBack" android:background="@drawable/arrowleft" android:layout_marginLeft="10dip"
     android:layout_marginTop="6dip"></ImageButton>

   </RelativeLayout>

Любой ответ на это?

Ответы [ 5 ]

2 голосов
/ 27 октября 2011

Установка высоты scrollView в wrap_content или fill_parent не будет иметь большого значения. попробовать

android:fillViewport="true"
0 голосов
/ 27 октября 2011

Я решил проблему.Это не хорошо, чтобы соответствовать представлению списка в представлении прокрутки.Так что я сделал, поместил 1 текстовый вид и вид изображения в один xml и накачал их в List Adapter.

Я поместил эти 2 поля в другой xml, скажем listbox2.xml

 <ImageView android:id="@+id/abtHome" android:layout_below="@+id/logoTop"
    android:src="@drawable/abouthome" android:scaleType="fitXY"
    android:layout_width="match_parent" android:maxWidth="230dip"
    android:layout_height="230dip">
</ImageView> 

<TextView android:id="@+id/tourcity" android:layout_below = "@+id/abtHome"
    android:layout_height="wrap_content" android:layout_width="match_parent"
    android:textSize="25dip" android:layout_centerHorizontal="true"
    android:editable="false" android:paddingTop="5dip" android:textColor="@color/white"
    android:paddingBottom="5dip" android:background="#80000000" android:gravity="center"></TextView>

Теперь внутри моего адаптера списка я делаю вот так

   public View getView(int position, View convertView, ViewGroup parent) {

    if(position == 0) {
        convertView = mInflater.inflate(R.layout.listbox2, null);
        TextView cityLabel = (TextView) convertView.findViewById(R.id.tourcity);
        cityLabel.setText("Some Text");
        return convertView;
    }

    else if (convertView == null || convertView.getTag() == null) {
        convertView = mInflater.inflate(R.layout.listbox, null);
        convertView.setOnClickListener(clickListener);
        holder = new ViewHolder();
        holder.view1 = (TextView) convertView.findViewById(R.id.listText);
        holder.desc = (TextView) convertView.findViewById(R.id.editText1);
        holder.index = (TextView) convertView.findViewById(R.id.index);
        holder.desc.setVisibility(View.GONE);
        holder.priceBtn = (Button) convertView.findViewById(R.id.prcBtn);
        holder.icon = (ImageView) convertView.findViewById(R.id.listIcon);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

        return convertView;
 }

Если позиция0, я надуваю этот новый xml, где я сохранил вышеупомянутые 2 поля, иначе он продолжается обычным способом.

Надеюсь, мой ответ ясен

0 голосов
/ 27 октября 2011

Ваш макет очень запутанный ... Как минимум, я могу выделить следующие наблюдения:

  • Используются конфликтующие теги.Например, в элементе "btnMap":

    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    
  • Элементы внутреннего уровня выровнены относительно элементов старшего уровня.Например, «abtHome», который расположен внутри ScrollView, выровнен относительно «logoTop», который расположен на верхнем уровне (так же, как ScrollView).
  • ListView используется внутри ScrollView.Если вы хотите добавить верхнюю или нижнюю часть представлений ListView, которые отличаются от элементов ListView, но должны прокручиваться с элементами ListView, вы должны использовать addHeaderView и addFooterView методы ListView.

Общий совет: лучше структурировать разметку.Определите основные элементы самого высокого уровня абстракции, а затем заполните их.

В вашем случае я бы сделал что-то вроде этого (если я правильно понимаю, чего вы хотели достичь):

Этоэто просто скелет компоновки и ViewGroup, который вы должны заменить на более подходящие контейнеры.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <!-- logoTop here -->
    </ViewGroup>

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!-- ListView and maybe some overlaying views here -->
    </ViewGroup>

    <ViewGroup
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <!-- barDown here -->
    </ViewGroup>
</LinearLayout>
0 голосов
/ 27 октября 2011

Я думаю, что проблема возникает из-за попытки включить ListView в ScrollView, поэтому вот решение без ScrollView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/logoTop"
        android:layout_below="@+id/logoTop"
        android:text="TextView" >
    </TextView>

    <ImageView
        android:id="@+id/logoTop"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/logotop" >
    </ImageView>

    <ImageView
        android:id="@+id/barDown"
        android:layout_width="match_parent"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:scaleType="fitXY"
        android:src="@drawable/bardown" >
    </ImageView>

    <ImageButton
        android:id="@+id/btnMap"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:background="@drawable/mapselector"
        android:scaleType="fitXY"
        android:src="@drawable/map" >
    </ImageButton>

    <ImageView
        android:id="@+id/abtHome"
        android:layout_width="match_parent"
        android:layout_height="230dip"
        android:layout_below="@+id/logoTop"
        android:maxWidth="230dip"
        android:scaleType="fitXY"
        android:src="@drawable/abouthome" >
    </ImageView>

    <ImageButton
        android:id="@+id/utBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/barDown"
        android:layout_marginRight="10dip"
        android:layout_marginTop="3dip"
        android:background="@drawable/utilitiesicon"
        android:scaleType="fitXY"
        android:src="@drawable/utilityselector" >
    </ImageButton>

    <TextView
        android:id="@+id/tourcity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/tourList"
        android:layout_centerHorizontal="true"
        android:background="#80000000"
        android:editable="false"
        android:gravity="center"
        android:paddingBottom="5dip"
        android:paddingTop="5dip"
        android:textColor="@color/white"
        android:textSize="25dip" >
    </TextView>

    <ListView
        android:id="@+id/tourList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/barDown"
        android:layout_below="@+id/abtHome"
        android:layout_centerInParent="true"
        android:background="#FFFFFF"
        android:cacheColorHint="#00000000"
        android:fadingEdge="horizontal"
        android:fastScrollEnabled="true"
        android:isScrollContainer="false"
        android:scrollbars="none"
        android:visibility="visible" >
    </ListView>

    <ImageButton
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/barDown"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="6dip"
        android:background="@drawable/arrowleft"
        android:src="@drawable/arrowselector" >
    </ImageButton>

</RelativeLayout>

Поскольку у меня нет всех ресурсов, я могуНа самом деле не вижу, как это выглядит, но я полагаю, что вы можете настроить параметры макета видов по своему усмотрению.

0 голосов
/ 27 октября 2011

Из описания, которое вы дали своей проблеме, кажется, что ваша высота ScrollView должна быть fillParent

...