TableRows are not converted correctly #68

Closed
pasviegas opened this Issue Nov 3, 2013 · 9 comments

Comments

Projects
None yet
2 participants
@pasviegas

Hey! I was trying to use the library, but I am not able to create TableRows correctly.

I went to the layout converter and It does not take in account the views inside the TableRow.

Do you have a working example of STableRow?

Thanks

@pocorall

This comment has been minimized.

Show comment
Hide comment
@pocorall

pocorall Nov 3, 2013

Owner

Would you list your xml layout you tried to convert?

Owner

pocorall commented Nov 3, 2013

Would you list your xml layout you tried to convert?

@pasviegas

This comment has been minimized.

Show comment
Hide comment
@pasviegas

pasviegas Nov 3, 2013

Sure

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <!-- 2 columns -->
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <TextView
            android:id="@+id/textView1"
            android:text="Column 1"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <Button
            android:id="@+id/button1"
            android:text="Column 2" />
    </TableRow>

    <!-- edittext span 2 column -->
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <EditText
            android:id="@+id/editText1"
            android:layout_span="2"
            android:text="Column 1 &amp; 2" />
    </TableRow>

    <!-- just draw a red line -->
    <View
        android:layout_height="2dip"
        android:background="#FF0000" />

    <!-- 3 columns -->
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <TextView
            android:id="@+id/textView2"
            android:text="Column 1"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <Button
            android:id="@+id/button2"
            android:text="Column 2" />

        <Button
            android:id="@+id/button3"
            android:text="Column 3" />
    </TableRow>

    <!-- display this button in 3rd column via layout_column(zero based) -->
    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <Button
            android:id="@+id/button4"
            android:layout_column="2"
            android:text="Column 3" />
    </TableRow>

    <!-- display this button in 2nd column via layout_column(zero based) -->
    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <Button
            android:id="@+id/button5"
            android:layout_column="1"
            android:text="Column 2" />
    </TableRow>

</TableLayout>

This is the result:

import android.view.ViewGroup.LayoutParams

override def onCreate(savedInstanceState: Bundle) {
  super.onCreate(savedInstanceState)

  contentView = new STableLayout {
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
  }.<<.fill.>>
}

Sure

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <!-- 2 columns -->
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <TextView
            android:id="@+id/textView1"
            android:text="Column 1"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <Button
            android:id="@+id/button1"
            android:text="Column 2" />
    </TableRow>

    <!-- edittext span 2 column -->
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <EditText
            android:id="@+id/editText1"
            android:layout_span="2"
            android:text="Column 1 &amp; 2" />
    </TableRow>

    <!-- just draw a red line -->
    <View
        android:layout_height="2dip"
        android:background="#FF0000" />

    <!-- 3 columns -->
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <TextView
            android:id="@+id/textView2"
            android:text="Column 1"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <Button
            android:id="@+id/button2"
            android:text="Column 2" />

        <Button
            android:id="@+id/button3"
            android:text="Column 3" />
    </TableRow>

    <!-- display this button in 3rd column via layout_column(zero based) -->
    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <Button
            android:id="@+id/button4"
            android:layout_column="2"
            android:text="Column 3" />
    </TableRow>

    <!-- display this button in 2nd column via layout_column(zero based) -->
    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <Button
            android:id="@+id/button5"
            android:layout_column="1"
            android:text="Column 2" />
    </TableRow>

</TableLayout>

This is the result:

import android.view.ViewGroup.LayoutParams

override def onCreate(savedInstanceState: Bundle) {
  super.onCreate(savedInstanceState)

  contentView = new STableLayout {
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
    STableRow().<<.height(LayoutParams.WRAP_CONTENT).width(LayoutParams.WRAP_CONTENT).>>.padding(5 dip)
  }.<<.fill.>>
}
@pocorall

This comment has been minimized.

Show comment
Hide comment
@pocorall

pocorall Nov 3, 2013

Owner

OK, definitely current version of Scaloid and its converter does not cover this issue. I will schedule it.

Owner

pocorall commented Nov 3, 2013

OK, definitely current version of Scaloid and its converter does not cover this issue. I will schedule it.

@pasviegas

This comment has been minimized.

Show comment
Hide comment
@pasviegas

pasviegas Nov 3, 2013

So, table rows are not working at all?

Is there anything I can do to help?

So, table rows are not working at all?

Is there anything I can do to help?

@pocorall

This comment has been minimized.

Show comment
Hide comment
@pocorall

pocorall Nov 3, 2013

Owner

Scaloid always has a workaround: you can use the xml layout using plain-old Android API.

https://github.com/pocorall/scaloid#migration-tip

And based on some resources that I found, STableRow should be added to Scaloid.

http://stackoverflow.com/questions/1528988/create-tablelayout-programatically
http://stackoverflow.com/questions/9683006/android-stretching-rows-in-tablelayout-programmatically

If you willing to contribute to Scaloid, would you fix this issue?

Owner

pocorall commented Nov 3, 2013

Scaloid always has a workaround: you can use the xml layout using plain-old Android API.

https://github.com/pocorall/scaloid#migration-tip

And based on some resources that I found, STableRow should be added to Scaloid.

http://stackoverflow.com/questions/1528988/create-tablelayout-programatically
http://stackoverflow.com/questions/9683006/android-stretching-rows-in-tablelayout-programmatically

If you willing to contribute to Scaloid, would you fix this issue?

@pasviegas

This comment has been minimized.

Show comment
Hide comment
@pasviegas

pasviegas Nov 4, 2013

I spiked it out in my project to see if I could get it working.

I don't know if I am in the right path

TableLayout

class ETableLayout()(implicit context: android.content.Context, parentVGroup: TraitViewGroup[_] = null)
    extends android.widget.TableLayout(context) with TraitTableLayout[ETableLayout] {

    def basis = this

    override val parentViewGroup = parentVGroup

    implicit def defaultLayoutParams[V <: View](v: V): LayoutParams[V] = new LayoutParams(v)

    override def +=(v: View) = {
      var viw = v
      viw = applyStyle(viw)
      basis.addView(viw, defaultLayoutParams(viw))
      basis
    }

    class LayoutParams[V <: View](v: V) extends TableLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f) with ViewGroupLayoutParams[LayoutParams[V], V] {
      def basis = this

      v.setLayoutParams(this)

      def parent = ETableLayout.this

      def >> : V = v
    }

  }

TableRow

class ETableRow()(implicit context: android.content.Context, parentVGroup: TraitViewGroup[_] = null)
    extends android.widget.TableRow(context) with TraitTableRow[ETableRow] {

    def basis = this

    override val parentViewGroup = parentVGroup

    implicit def defaultLayoutParams[V <: View](v: V): LayoutParams[V] = new LayoutParams(v)

    class LayoutParams[V <: View](v: V) extends TableRow.LayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f) with ViewGroupLayoutParams[LayoutParams[V], V] {
      def basis = this

      v.setLayoutParams(this)

      def parent = ETableRow.this

      def >> : V = v
    }

  }

Am I missing something?

I spiked it out in my project to see if I could get it working.

I don't know if I am in the right path

TableLayout

class ETableLayout()(implicit context: android.content.Context, parentVGroup: TraitViewGroup[_] = null)
    extends android.widget.TableLayout(context) with TraitTableLayout[ETableLayout] {

    def basis = this

    override val parentViewGroup = parentVGroup

    implicit def defaultLayoutParams[V <: View](v: V): LayoutParams[V] = new LayoutParams(v)

    override def +=(v: View) = {
      var viw = v
      viw = applyStyle(viw)
      basis.addView(viw, defaultLayoutParams(viw))
      basis
    }

    class LayoutParams[V <: View](v: V) extends TableLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f) with ViewGroupLayoutParams[LayoutParams[V], V] {
      def basis = this

      v.setLayoutParams(this)

      def parent = ETableLayout.this

      def >> : V = v
    }

  }

TableRow

class ETableRow()(implicit context: android.content.Context, parentVGroup: TraitViewGroup[_] = null)
    extends android.widget.TableRow(context) with TraitTableRow[ETableRow] {

    def basis = this

    override val parentViewGroup = parentVGroup

    implicit def defaultLayoutParams[V <: View](v: V): LayoutParams[V] = new LayoutParams(v)

    class LayoutParams[V <: View](v: V) extends TableRow.LayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f) with ViewGroupLayoutParams[LayoutParams[V], V] {
      def basis = this

      v.setLayoutParams(this)

      def parent = ETableRow.this

      def >> : V = v
    }

  }

Am I missing something?

@pocorall

This comment has been minimized.

Show comment
Hide comment
@pocorall

pocorall Jan 3, 2014

Owner

Fixed to support STableLayout and STableRow

d751898

Layout converter will be fixed as well.

Owner

pocorall commented Jan 3, 2014

Fixed to support STableLayout and STableRow

d751898

Layout converter will be fixed as well.

@pasviegas

This comment has been minimized.

Show comment
Hide comment

Thanks!!

@guersam guersam referenced this issue in pocorall/scaloid-layout-converter Jan 20, 2014

Merged

STableRow support #5

@pocorall

This comment has been minimized.

Show comment
Hide comment
@pocorall

pocorall Jan 21, 2014

Owner

@guersam did an awesome job on fixing this issue on layout converter. Now the example xml layout above is converted as:

onCreate {

  contentView = new STableLayout {
    this += new STableRow {
      STextView("Column 1").textAppearance(android.R.attr.textAppearanceLarge)
      SButton("Column 2")
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      SEditText().<<.span(2).>>.text("Column 1 & 2")
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      STextView("Column 1").textAppearance(android.R.attr.textAppearanceLarge)
      SButton("Column 2")
      SButton("Column 3")
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      SButton("Column 3").<<.column(2).>>
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      SButton("Column 2").<<.column(1).>>
    }.<<.wrap.>>.padding(5 dip)
  }.<<.fill.>>
}

Thanks @guersam!

Owner

pocorall commented Jan 21, 2014

@guersam did an awesome job on fixing this issue on layout converter. Now the example xml layout above is converted as:

onCreate {

  contentView = new STableLayout {
    this += new STableRow {
      STextView("Column 1").textAppearance(android.R.attr.textAppearanceLarge)
      SButton("Column 2")
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      SEditText().<<.span(2).>>.text("Column 1 & 2")
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      STextView("Column 1").textAppearance(android.R.attr.textAppearanceLarge)
      SButton("Column 2")
      SButton("Column 3")
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      SButton("Column 3").<<.column(2).>>
    }.<<.wrap.>>.padding(5 dip)
    this += new STableRow {
      SButton("Column 2").<<.column(1).>>
    }.<<.wrap.>>.padding(5 dip)
  }.<<.fill.>>
}

Thanks @guersam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment