本文整理汇总了Scala中android.util.DisplayMetrics类的典型用法代码示例。如果您正苦于以下问题:Scala DisplayMetrics类的具体用法?Scala DisplayMetrics怎么用?Scala DisplayMetrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DisplayMetrics类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AlphabetDetailsAdapter
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.support.v7.widget.RecyclerView
import android.util.DisplayMetrics
import android.view.View.OnClickListener
import android.view.{View, ViewGroup}
import sword.langbook.android.R
import sword.langbook.android.viewholders.SymbolViewHolder
import sword.langbook.db.Alphabet
object AlphabetDetailsAdapter {
def apply(activity: Activity, alphabet: Alphabet) = {
val metrics = new DisplayMetrics()
activity.getWindowManager.getDefaultDisplay.getMetrics(metrics)
val columns = metrics.widthPixels / activity.getResources.getDimensionPixelSize(R.dimen.alphabetDetailsSymbolSide)
new AlphabetDetailsAdapter(activity, alphabet, columns)
}
}
case class AlphabetDetailsAdapter(activity: Activity, alphabet: Alphabet, spanCount: Int) extends RecyclerView.Adapter[SymbolViewHolder] {
val symbols = alphabet.symbols.toSeq.sortWith(_.unicode < _.unicode)
val chars = symbols.map(_.unicode.toChar)
override val getItemCount = symbols.size
override def onCreateViewHolder(viewGroup: ViewGroup, viewType: Int) = {
SymbolViewHolder.newInstance(viewGroup)
}
override def onBindViewHolder(vh: SymbolViewHolder, position: Int): Unit = {
vh.textView.setText("" + chars(position))
vh.textView.setOnClickListener(new OnClickListener {
override def onClick(v: View): Unit = {
SymbolDetails.openWith(activity, symbol = symbols(position))
}
})
}
}