Giter Site home page Giter Site logo

Comments (9)

pocorall avatar pocorall commented on June 2, 2024

Would you list your xml layout you tried to convert?

from scaloid.

pasviegas avatar pasviegas commented on June 2, 2024

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.>>
}

from scaloid.

pocorall avatar pocorall commented on June 2, 2024

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

from scaloid.

pasviegas avatar pasviegas commented on June 2, 2024

So, table rows are not working at all?

Is there anything I can do to help?

from scaloid.

pocorall avatar pocorall commented on June 2, 2024

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?

from scaloid.

pasviegas avatar pasviegas commented on June 2, 2024

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?

from scaloid.

pocorall avatar pocorall commented on June 2, 2024

Fixed to support STableLayout and STableRow

d751898

Layout converter will be fixed as well.

from scaloid.

pasviegas avatar pasviegas commented on June 2, 2024

Thanks!!

from scaloid.

pocorall avatar pocorall commented on June 2, 2024

@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!

from scaloid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.