Problem with Custom View used as cell of table layout

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problem with Custom View used as cell of table layout

Postby Savotin » Wed Dec 19, 2007 9:08 am

Hello!

I have problem with Using of my Custom View in the table layout.

This is example of code:

This is custom view which just draw line:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class CanvasTest extends View {
  2.  
  3. CanvasTest(Context context, AttributeSet attrs, Map inflateParams) {
  4.  
  5. super(context, attrs, inflateParams);
  6.  
  7. // TODO Auto-generated constructor stub
  8.  
  9. } @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); canvas.drawLine(0, 0, this.getWidth()-2, 0, paint); }
  10.  
  11. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


This is example of using custom view with table layout:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. CanvasTest child = new CanvasTest(context, attrs, inflateParams);
  3.  
  4. child.setPreferredHeight(15);
  5.  
  6. child.setPreferredWidth(15);
  7.  
  8. daysOfWeek3.addView(child, new TableRow.LayoutParams());
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


The problem is: setPreferredHeight does not work, so Width has size 15, but Height is always 128, but as you see i set height to 15.

does somebody know what is the problem here?

Thanks in advance!

Artem
Savotin
Freshman
Freshman
 
Posts: 2
Joined: Wed Dec 19, 2007 8:52 am

Top

Postby plusminus » Wed Dec 19, 2007 6:08 pm

Hello Savotin,

perhaps the LayoutParams redefine the width of the View?

Try setting the width after-wards. . .

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Savotin » Wed Dec 19, 2007 9:15 pm

Hello!

Ok i found solution seems that it was problem of xml layout file:


When it did not work my xml looks like:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
   
<TextView id="@+id/text" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Text from Custom_Date_Picker"
    />

<TableLayout id="@+id/grid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
</TableLayout>
   
</LinearLayout>


And after changes:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
   
<TextView id="@+id/text" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Text from Custom_Date_Picker"
    />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TableLayout id="@+id/grid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
</TableLayout>
</ScrollView>
   
</LinearLayout>


So you can see that necessary to border TableLayout by ScrollView

but if true is very scrappy method and i don't understand why does it work

i will try to find out another method
Savotin
Freshman
Freshman
 
Posts: 2
Joined: Wed Dec 19, 2007 8:52 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests