-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
text does not scale in TextView #12
Comments
https://s.amsu.ng/7imFzw7HHTxN and buttons overlap table.add(android.widget.Button(this))
table.add(android.widget.Button(this)) |
this is fixed for buttons by specifying both fill and expand but it does not work for textview as it aligns to the top left/right of the cell |
Generally you size a root table to the entire area for your UI, then you add everything to that table. From the screenshots it looks like it is sized to the screen but to be sure, are you sizing the root-most table? I'm afraid I don't have an Android development environment setup, so I can't test things right now. Also it's been a long time since I punished myself with Android's UI toolkit! If we can get you rolling with TableLayout though, much of the pain goes away. BaseTableLayout uses AndroidToolkit#getPrefWidth/Height which is using view.getMeasuredWidth/Height() -- are those values what you'd expect? If they were large, it could explain why the buttons overlap: TableLayout thinks the button's preferred size is very large, larger than the available space. Can you check AndroidToolkit.density? Does it help if you set it to 1 after calling |
this is confusing but ill try |
setting AndroidToolkit.density to 1F (short for https://s.amsu.ng/iJpYtBV1XR1N AndroidToolkit.setup(this, R.drawable::class.java)
AndroidToolkit.density = 1F
Constraint.addView(
Table().also {
it.tableLayout.debug()
it.defaults().expand()
it.add(Button(this))
it.add(Button(this))
}
) |
now, how to i make sure that i am sizing the root most table? |
layout/table_empty.xml (R.layout.table_empty) <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/ConstraintOnly">
</android.support.constraint.ConstraintLayout> com/example/broadcastConsole/grid/MainActivity.kt package com.example.broadcastConsole.grid
import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.*
import com.esotericsoftware.tablelayout.android.AndroidToolkit
import com.esotericsoftware.tablelayout.android.Table
import com.example.broadcastConsole.R
import kotlinx.android.synthetic.main.table_empty.*
class MainActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.table_empty)
fun t(a: String): TextView {
val textView = TextView(this)
textView.text = a
textView.setTextColor(Color.WHITE)
textView.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM)
textView.setPadding(0, 0, 0, 0)
textView.setTypeface(Typeface.MONOSPACE, Typeface.BOLD)
return textView
}
AndroidToolkit.setup(this, R.drawable::class.java)
AndroidToolkit.density = 1F
ConstraintOnly.addView(
Table().also {
it.tableLayout.debug()
it.defaults().expand().fill()
it.add(Button(this))
it.add(Button(this))
it.row()
it.add(t("B"))
it.add(t("B"))
}
)
}
} app/src/main/AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.example.broadcastConsole">
<dist:module dist:instant="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.example.broadcastConsole.grid.MainActivity"
android:label="@string/title_activity_grid"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest> |
table.xml
setContentView(R.layout.table) https://s.amsu.ng/QXUJaxWg1IgN and this is what i get if i attempt to recreate it fun t(a: String): TextView = TextView(this).also {
it.text = a
it.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM)
it.setTypeface(Typeface.MONOSPACE, Typeface.BOLD)
it.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
it.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
}
setContentView(R.layout.table_empty)
AndroidToolkit.setup(this, R.drawable::class.java)
AndroidToolkit.density = 1F
ConstraintOnly.addView(
LinearLayout(this).also {
it.addView(
Table().also {
it.tableLayout.debug()
it.add(t("p")).center().fill().expand()
it.add(t("r")).center().fill().expand()
it.row()
it.add(t("e")).center().fill().expand()
it.add(t("p")).center().fill().expand()
it.row()
it.add(t("r")).center().fill().expand()
it.add(t("e")).center().fill().expand()
it.row()
it.add(t("c")).center().fill().expand()
it.add(t("o")).center().fill().expand()
}
, ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
it.orientation = LinearLayout.VERTICAL
}
) |
it may be due to the all i know is that android:stretchColumns="*"
android:weightSum="4" and android:layout_weight="1" |
fun t(a: String): TextView = TextView(this).also {
it.text = a
it.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM)
it.setTypeface(Typeface.MONOSPACE, Typeface.BOLD)
it.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
it.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
} in which ConstraintOnly.addView(t("P")) results in https://s.amsu.ng/gm0o3mJc2wqN ConstraintOnly.addView(
Table().also {
it.add(t("P"))
}
) results in https://s.amsu.ng/MtMIFlFPyimN |
OK. I don't remember what the density stuff was about, so I'll add a commit to keep it at 1.
Now that we have delegate methods, you can just use
You use whatever Android UI stuff to make the root table the size you want, in the position you want. I'm afraid the Android UI XML doesn't mean anything to me (that is some nasty stuff). The Android UI layouting is poor, TableLayout replaces it (once you have sized and positioned the root table). Also ConstraintOnly addView, LinearLayout, stretchColumns, layout_weight, etc are unfamiliar to me. |
ok, can you give me an example of a root most table |
Not any time soon, I don't have Android stuff setup (and I honestly hate it). Replace the table with a button (or ViewGroup or anything else). Make the button take up the whole screen (or whatever area you want for your UI). Once you have that working, replace the button with the table and that is your root table. Add the rest of your UI to the root table and mostly you never have to deal with nasty Android UI again. |
https://s.amsu.ng/9DXIX8eEL06N
The text was updated successfully, but these errors were encountered: