Separator padding , ignoring it
Asked Answered
C

2

8

I have a problem with this separator:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <padding android:left="10dip" android:right="10dip"/>
    <solid android:color="@color/listSeparator"/>
    <size android:height="1px" />
</shape>

I'm trying to make a little margin/padding in the left/right of the listview component (using a relative on it , not a ListView Object) . Then when i try to put it this way...

getListView().setDivider(getResources().getDrawable(R.drawable.song_separator));

... it's directly ignored , putting a full layout separator .

Now i don't know what is the problem , but i know that :

  • I can't put a margin in all ListView , cause i want the listHeader fill_parent
  • I have tried to put a false border , but it isn't nice looking when i change it's background color , putting me a separator space.

Any idea?

MODIFIED

My last partial solution is to put an ImageView , aligned next to the parent bottom . This is partial cause it puts on the bottom but not on the original divider.

If someone can tell me how to put that ImageView on the exact line of the divider, i would give him the +50 too.

Crenation answered 18/10, 2011 at 12:47 Comment(6)
can you post the code where you can set the divider?Mythicize
I'm putting it well cause when i change the color or the drawable , it runs. no more code is involved.Crenation
android:divider="@drawable/song_separator" in listview of layout xml fileDiachronic
@pankaj it's not a ListView XML item , it doesn't accept android:divider tag.Crenation
@Hiral it can be both . But it must be relative to dip measure . Then i think it can't be a fixed image . If your experiments found something else , i would be pleased to give you the +50 .Crenation
@Crenation did you ever figure this out? I'm trying to do the exact same thing. It seems the separators are stretched to the Width of the ListView. The only way I can think of off the top of my head would be to make your own Drawable that actually does the padding itself rather than having the layout do it -- but this really shouldn't be necessary.Hildebrand
H
1

Quiroga so my first bet would be to make the code more debugable by spliting the method call up into individual lines.

ListView lview = getListView();
if (lview != null){
  Resources res = getResources();
  if (res != null) {
       Drawable dable = res.getDrawable(R.drawable.song_separator);
       if (dable != null){
           lview.setDivider(dable)
       }
  }
} else {
   //Log in some way that you have a problem.
}

I know it looks kind of over complicated but that way you can make sure that the Drawable is found and is the correct one and then properly assigned to the ListView.

Another thing you can try is just assigning a different maybe platform specific separator and see if that works properly.

Also try to get your hands on the Android Source Code it is back online if you add that to your Java Project you can debug into the Platform classes and debug deep into the platform code.

So this isn't really a solution for your problem but maybe it can help you find the solution.

Hat answered 21/10, 2011 at 3:33 Comment(2)
I have try your code also to confirm that the listView is ok and getResources() too but i have the problem . My last solution is to put an ImageView , width that padding aligned on the bottom . If someone can tell me how to put that ImageView on the exact line of the separator , i would give him the +50 too.Crenation
@Crenation and this also doesn't work for the last ListView element if you want dividers only shown in the middle. Small detail but still noteworthy.Hildebrand
P
1

Put the header in a separate file and access it as:

public class AuditActivity extends ListActivity {

Budget budget;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.audit);
    ListView lv = getListView();
    LayoutInflater infalter = getLayoutInflater();
    ViewGroup header = (ViewGroup) infalter.inflate(R.layout.header, lv, false);
    lv.addHeaderView(header);
    budget = new Budget(this);
    /*
    try {
        test = budget.getTransactions();
        showEvents(test);
    } finally {

    }
    */

// switchTabSpecial(); }

Follow this link .......it has a detailed info,use RelativeLayout instead of Linear One, I hope this will help you. Android: Adding static header to the top of a ListActivity

Precept answered 26/10, 2011 at 14:12 Comment(1)
I have the listHeader separated into another layout . It's strange cause margin affects header , since header is inflated into the list (like you show me).Crenation

© 2022 - 2024 — McMap. All rights reserved.