使用RecyclerView时,是否可以将项目高度设置为两个文本行的高度?
假设一个项目上面有一个TextView。某些项目可能包含较长的文本,而该文本不能排成一行。我将最大行数限制为2。但是,如果某些项的高度为1行,而另一些项的高度为2行,则看起来很难看。因此,我希望所有项目都具有2行的高度,即使该项目只有一行文本。
我可以在DP中设置项目的高度,但是问题是,由于我使用系统字体设置,因此很难对高度的数字值进行硬编码。一些系统可能具有较大的字体和较大的边距。
我想做的事可能吗?
假设我的“底部工作表”中包含以下几行小部件。如果我想只显示前两行(即前两行LinearLayout),而不显示下面的其余小部件。我不希望这些内容一开始就被看到。如何设置正确的窥视高度?硬编码app:behavior_peekHeight可能无法工作,因此我需要以编程方式进行设置,但是如何计算高度呢?
还是有更推荐的方法来获得相同的结果?我的意思是,如果我测试Google Maps,长按位置会首先仅将标题部分显示为底部,但是当我尝试向上滚动底部时,感觉好像标题部分(可能不是真正的标题部分)底页)替换为包含所有元素的真实底页。如果我的解释还不够,请自己尝试使用Google地图。
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView/>
<android.support.v7.widget.AppCompatSpinner/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView/>
<TextView/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView/>
<TextView/>
</LinearLayout>
<android.support.v7.widget.RecyclerView/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud) 我将现有的ASP.NET Core 2.2项目升级到3.0。我有一个返回JSON的方法,该方法在2.2中可用,但是在3.0中,它导致“不支持集合类型'Newtonsoft.Json.Linq.JToken'。” 在返回。
[HttpGet()]
public async Task<JsonResult> Get()
{
var res = some class object in a third-party library;
return new JsonResult(res);
}
Run Code Online (Sandbox Code Playgroud)
我搜索了Google,发现Microsoft已将Newtonsoft Json替换为System.Text.Json,但我没有明确使用Newtonsoft Json。在项目的“框架”中,我可以看到Newtonsoft Json,并删除了它和using Newtonsoft.Json.Linq语句,但是结果是相同的。如何不使用Newtonsoft Json?
错误消息是:
System.NotSupportedException: The collection type 'Newtonsoft.Json.Linq.JToken' is not supported.
at System.Text.Json.JsonClassInfo.GetElementType(Type propertyType, Type parentType, MemberInfo memberInfo, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo.CreateProperty(Type declaredPropertyType, Type runtimePropertyType, Type implementedPropertyType, PropertyInfo propertyInfo, Type parentClassType, JsonConverter converter, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo.AddProperty(Type propertyType, PropertyInfo propertyInfo, Type classType, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo.AddPolicyProperty(Type propertyType, JsonSerializerOptions …Run Code Online (Sandbox Code Playgroud) 我添加了一个定期执行某些操作的后台服务,例如官方示例。
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddHostedService<TimedHostedService>(); <-- here
services.AddSingleton<WeatherForecastService>();
}
Run Code Online (Sandbox Code Playgroud)
TimedHostedService有和。 最终,我想在网络浏览器中调用这些。StartAsyncStopAsync
在FetchData.razor默认脚手架的文件中,我尝试直接引用该服务,但这不起作用。因此,我添加了Start和Stop方法WeatherForecastService并在单击事件上调用它们。
<button @onclick="()=> { ForecastService.Stop(); }">Stop</button>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,我不知道如何TimedHostedService在Stop的方法中获取 的运行实例WeatherForecastService。
public class WeatherForecastService
{
....
public void Stop()
{
//how to get TimedHostedService instance?
}
....
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用依赖注入来获取服务提供者,但GetService返回 null。
IServiceProvider sp;
public WeatherForecastService(IServiceProvider sp)
{
this.sp = sp;
}
public void Stop()
{
var ts = sp.GetService(typeof(TimedHostedService)) as …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码来播放流(既有视频又有音频)。但是如果我想要同时同步一个视频流和一个单独的视频流音频流怎么办?例如,假设有
video.mp4和都audio.mp3属于video1且 具有相同的长度,1:23:34。我可以使用一个 ExoPlayer 同步播放video.mp4它们audio.mp3,就像它们是一个流一样吗?用户必须能够暂停/播放/搜索,并且相同的操作应该应用于两个流。
如果没有,我必须使用两个 ExoPlayer,一个用于视频,一个用于音频,如何同步音频和视频?
var uri = Uri.parse(url);
var df = DefaultHttpDataSourceFactory(url);
var ms = ExtractorMediaSource(uri, df, DefaultExtractorsFactory(), null, null);
exoPlayer.playWhenReady=true;
exoPlayer.prepare(ms);
Run Code Online (Sandbox Code Playgroud) 为什么下面的代码不播放声音?它为 play() 返回“true”,但我听不到任何声音。
let path = "/Users/account/Music/sound.mp3";
let fileURL = NSURL(fileURLWithPath: path)
var Player = AVAudioPlayer(contentsOfURL:fileURL, error:nil);
Player.delegate = self;
Player.prepareToPlay();
Player.volume = 1.0;
var res = Player.play();
println(res);
Run Code Online (Sandbox Code Playgroud)
如果我改用以下代码,我可以听到声音。
var inFileURL:CFURL = fileURL!;
var mySound = UnsafeMutablePointer<SystemSoundID>.alloc(sizeof(SystemSoundID));
AudioServicesCreateSystemSoundID(inFileURL, mySound);
AudioServicesPlaySystemSound(mySound.memory)
Run Code Online (Sandbox Code Playgroud)
我为片段调用了 setRetainInstance(true) 。我在片段上添加了 EditText 和 TextView。旋转时,EditText 中的文本保留下来,但 TextView 中的文本消失了。
我想我可以手动恢复TextView的文本,但我想知道为什么系统会自动恢复EditText的文本,而不是TextView。我做错什么了吗?
重现步骤。
结果
EditText 有“android”,但 TextView 是空的。
我的片段
public class MyFragment extends Fragment
{
private static final String TAG = "MyFragment";
EditText etInput;
Button btnTest1;
TextView tvMessage;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
Log.d(TAG, "onCreateView()");
View v= inflater.inflate(R.layout.my_fragment, container, false);
etInput = (EditText)v.findViewById(R.id.etInput);
btnTest1 = (Button)v.findViewById(R.id.btnTest1);
btnTest1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{ …Run Code Online (Sandbox Code Playgroud) 例如,如果List包含{1,2,3,4,5},则调用Sort()不会更改任何内容.但如果列表包含{1,2,4,3,5},则调用Sort()将更改顺序.
有没有办法知道是否有任何Sort()改变?该方法返回void.
PS
实际上,我在发布此问题之前对此进行了测试.这个想法是x以前的项目y,所以如果需要返回负值,则会发生交换.不幸的是,它没有用......但为什么呢?
class IntComp : IComparer<int>
{
public int Compare(int x, int y)
{
var result = x - y;
if (result < 0)
_IsChanged = true;
return result;
}
private bool _IsChanged = false;
public bool IsChanged()
{
var result = _IsChanged;
_IsChanged = false;
return result;
}
}
var list = new List<int>() {};
Random r = new …Run Code Online (Sandbox Code Playgroud) 我可以找到的所有格式都是MS文档中的格式。当尝试实现文件拖放(从我的应用程序到Windows的文件浏览器)时,我收到许多GetData要求提供cfFormat值的请求,例如-16230,-15835,-15834,但我不知道它们是什么。
[当我尝试使用该DoDragDrop功能将文件名从应用程序拖到文件资源管理器时,显示完整日志。]
Mouse Down
EnumFormatEtc
EnumFormatEtc::Next(1)
EnumFormatEtc::Next(1)
EnumFormatEtc::Reset
EnumFormatEtc::Next(1)
EnumFormatEtc::Next(1)
QueryGetData(cf = 15, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16230, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15835, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15834, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15833, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT) …Run Code Online (Sandbox Code Playgroud) 尽管我很熟悉单例,但 Dart 的工厂还是令人困惑。我看到了一个现有的问题,但我从答案中得到的唯一信息是该名称可以是以 _ 开头的任何标识符。尽管这个人问了为什么应该这样称呼它,但答案似乎并没有解释这一点。
如果我注释掉该Dog._internal();行,我会得到Method not found: 'Dog._internal'.它看起来像调用一个方法,但它像 C 的函数原型吗?但它没有返回类型。有人可以Dog._internal();向我解释一下这条线吗?
class Dog
{
static final Dog dog = Dog._internal();
//Dog._internal();
factory Dog()
{
return dog;
}
}
Run Code Online (Sandbox Code Playgroud) android ×4
asp.net-core ×2
c# ×2
audio ×1
avfoundation ×1
blazor ×1
bottom-sheet ×1
dart ×1
exoplayer2.x ×1
macos ×1
swift ×1
winapi ×1