1

the xml file:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/singleProp"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:visibility="gone">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/propertyImg"/>


    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/propertyData"
        android:layout_below="@id/propertyImg">

    </ListView>


</RelativeLayout>

With the above codes, the image will be fixed at top-center position. With CSS terms in html, the style of that image view is style="position:fixed" but what I want is style="position:relative".

For example, enter image description here

I hope the picture can illustrate the idea. May I know how I should modify my codes?

ykn121
  • 835
  • 1
  • 9
  • 28

6 Answers6

2

Let me elaborate a bit more on mark.zhai`s answer, since it's the only one that I find to be the proper approach.

First of all I wanna point out that you should think about implementing your list with a RecyclerView instead of ListView (right now it's generally favoured to use a RecyclerView; ListView is getting kinda deprecated)...

If you want to be sure that your ImageView works nicely (scroll-wise) with your list (without too much "side-work" on scroll integration), you should implement it as a first item of your list. If you stick with your ListView you can use the header function of it and add your ImageView with ListView's method addHeaderView. If you decide to move to a RecyclerView (which I think you should), you can accomplish that in a bit more difficult manner (more on that for example here).

Community
  • 1
  • 1
Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132
1

why don't u make the imageview an item of the listview

markzhai
  • 46
  • 1
  • 2
1

For this you need to create a custom listview which having the first item as a image view and later having all your list items. Probably you can control this in your adapter getview method by the use of position(int)

For example if Position is equal to '0' show only image view and if position is not equal to '0' show your rest elements by using Visibility

Note: here their might be a chance of performance issues as it is loading the unnecessary views every time

King of Masses
  • 18,405
  • 4
  • 60
  • 77
0

To achieve this, you need to scrolling the complete layout. In general case, when you fling on a list view, only the item within the list view moves. Check this link.

Anitha Manikandan
  • 1,160
  • 7
  • 19
0

I'm not entirely sure what you're asking, as I don't know a lot about CSS, but you can check out this link which describes aligning elements within a Relative Layout.

You might want to try adding alignParentLeft or alignParentRight. Remember margins are external to the object and padding is internal. For example to move the image 20dp from the left you would:

<ImageView
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/propertyImg"/>

Here are some useful links about mastering Relative Layouts:

Relative Layout Params

Moving Elements Around in a Relative Layout Tutorial

Another RelativeLayout Example

Margins and Padding

RheeBee
  • 195
  • 2
  • 11
0

Why don't you use layout_below to take your layout below whatever you want, and use layout_gravity to set it's gravity. You can check these Link to get you better understand, it will help you in these problem.

ULHAS PATIL
  • 862
  • 8
  • 19