- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我想根据各种设备大小或 devicePixelRatio 值缩放我的 flutter 应用程序中的文本。我知道 flutter 应该根据 devicePixelRatio 值缩放文本,所以我以这种方式更改了我的代码,但它在我的代码中不起作用。
这是我的代码:
class MyHomePage extends StatefulWidget {
@override
MyHomePageState createState() => new MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
TextStyle style50 = new TextStyle(
inherit: true,
fontSize: 50.0,
color: Colors.white,
);
TextStyle style19 = new TextStyle(
inherit: true,
color: Colors.white,
fontSize: 19.0,
fontFamily: 'helvetica_neue',
);
TextStyle style15White = new TextStyle(
inherit: true,
color: Colors.white,
fontSize: 15.0,
fontFamily: 'helvetica_neue',
);
TextStyle style15Green = new TextStyle(
inherit: true,
color: Colors.green,
fontSize: 15.0,
fontFamily: 'helvetica_neue',
);
return new Scaffold(
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/home_page_background.png"),
fit: BoxFit.cover,
),
),
child: new Container(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
margin: new EdgeInsets.only(top: 160.0),
child: new Text(
'JAHMAIKA',
textAlign: TextAlign.center,
style: style50,
),
),
new Container(
margin: new EdgeInsets.only(top: 230.0),
child: new FlatButton(
child: new Container(
padding: new EdgeInsets.only(
left: 45.0, right: 45.0, top: 15.0, bottom: 15.0),
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: new BorderRadius.all(
new Radius.elliptical(40.0, 50.0)),
border: new Border.all(
color: Colors.white,
),
),
child: new Text(
'Create an account',
style: style19,
),
),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new SignUpPage()),
);
}),
),
new Container(
margin: new EdgeInsets.only(top: 16.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
child: new Text(
'Already have an account?',
textAlign: TextAlign.center,
style: style15White,
),
),
new GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new SignInPage()),
);
},
child: new Container(
margin: new EdgeInsets.only(left: 16.0),
child: new Text('Login',
textAlign: TextAlign.center, style: style15Green),
),
),
],
),
),
],
),
)),
);
}
}
但这行不通。各种设备中的文本字体大小没有变化。请帮助我。
最佳答案
您是否尝试过根据 MediaQuery.of(context).size.width
的比例计算 fontSize
?
使用基本设备设置尺寸,并使用它的宽度来计算其他设备的比例尺寸。
...
Widget build(BuildContext context) {
// 414.0 is the width of an iPhone 7plus
double fs = 50.0 * MediaQuery.of(context).size.width / 414.0;
// print("MediaQuery.of(context).size.width=${MediaQuery.of(context).size.width}");
// print("fs=$fs");
TextStyle style50 = new TextStyle(
inherit: true,
fontSize: fs,
color: Colors.white,
);
...
关于dart - TextSize 不会根据 deviceSize 或 devicePixelRatio 进行缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51184878/
我设法使用微调器更改特定文本的颜色。但现在我想用另一个微调器更改相同文本的大小。我将颜色盒放入开关函数中以更改颜色。 像这样 switch (i) { case 0:
如何支持不同屏幕尺寸的不同设备的文本大小?我已经尝试为不同的屏幕提供不同维度的 xml,但它没有有效地工作。 值(value)观大值值小值-sw600dp值-sw720dp值-sw800dp 最佳答案
我正在研究为我的 textPaint 动态设置文本大小的选项。我希望设置 textSize 值逐渐增加直到到达屏幕中心并逐渐减小直到屏幕底部。 1 2 3 4 5 6 7 8 9 截至目前,我将文本大
我已经为大屏幕上的所有文本按钮制作了自定义样式 @color/button_color 30dp true false 现在我想要普通屏幕的小按钮,我添加了新样式,
我已将西类牙语和法语添加到我的应用程序中,但一些措辞在西类牙语中比英语中更长。访问 values-es/string.xml 文件时如何更改文本大小 最佳答案 为此,您可以使用 dimens.xml
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.result_font));
我有以下布局: 还有这个样式定义:
有些应用程序可以更改主屏幕小部件中文本的字体大小。一个例子是 https://play.google.com/store/apps/details?id=org.zooper.zwfree 但是主屏幕
是否可以在 CSS 中设置文本大小,使其适应容器宽度? 我为此做了一个例子。左边的容器很小,这应该使字体大小小于右边的容器。我知道这是如何用 JavaScript 完成的,但我也可以用纯 CSS 来完
我正在尝试使用 PIL 来预先计算给定文本行在给定字体和大小下的大小。 PIL 似乎或多或少是唯一可行的解决方案。 我不确定font.textsize(..) 返回值的单位是什么。 doc没有具体
我想更改我的微调器背景颜色和微调器中每个项目的文本大小,我已经对与我的问题类似的问题进行了一些回答但没有得到答案天气我们可以改变一个的文本大小/背景颜色微调器与否?如果有人有一个简单的答案,我将感谢他
我正在使用 ActionBarSherlock 字幕并尝试使用样式更改字幕文本大小,但似乎不起作用。我对主题不太熟悉,所以..我该如何更改?? 提前致谢 最佳答案 @style/Widget
我正在我的 Android 应用程序中实现 Web View 以获取动态文本。但问题是文本大小在不同的屏幕尺寸下更大/更小。如何解决这个问题?我正在这样使用.. webSettings.setDefa
我正在使用具有一些不同首选项的 PreferenceScreen。我还使用了扩展 DialogPreference 的自定义首选项。现在自定义 DialogPreference 的字体大小与其他首选项
我将使用 MotionLayout 为文本大小变化设置动画。 我对开始状态执行以下操作 下面是结束状态 因此,看起来大小实际上在变化,但它比 14sp-16sp 大得多 那么,如何正确改变文字大小
我将 wear 模块添加到现有应用程序中,并提供另一个模块(处理 Auth 和 Network 任务)的支持。当我们构建时,gradle 显示以下错误: duplicate resource attr
我已经实现了一个自定义 TextView,然后我需要更改它的文本大小以供将来使用。在那一步,我决定使用 style.xml 和 attr.xml 定制它的 textSize 但是,当我的自定义布局膨胀
假设我有一个 TextView特定大小(实际上并不重要...... fill_parent,20dip,等等)。是否可以在不进行大量数学计算的情况下告诉文本缩小/增大大小以适应可用空间? 最佳答案 好
我有一个 Xamarin Android 项目,我在其中使用维度文件为不同的屏幕尺寸/分辨率指定文本大小、填充、边距等。 我注意到直接在布局中设置值和在代码中设置值之间存在明显差异。 例如,如果我将以
我正在尝试找到一种方法来在选择时更改 Tab Title 的文本大小。到现在没有导出。希望有人能帮助我。 我的代码如下: XML: 用于 tabTextAppearance 的样式:
我是一名优秀的程序员,十分优秀!