如何解决Xamarin Android背景上的启动画面两种颜色
我需要显示一个初始屏幕,该屏幕将屏幕分为两种颜色,占50%。此外,当您将设备从纵向旋转到横向时,我需要保持此状态。如何实现这种布局?
- 肖像:
- 风景:
目前,我有以下代码,但是这里我有固定大小( 440dp ),我需要一个具有百分比大小的解决方案:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:height="440dp" android:gravity="fill_horizontal|top">
<color android:color="@color/yellow"/>
</item>
<item android:height="440dp" android:gravity="fill_horizontal|bottom">
<color android:color="@color/red"/>
</item>
</layer-list>
解决方法
您可以使用Layout来执行此操作,例如LinearLayout或AbsoluteLayout。
首先,创建新的布局名称Splash-layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00ff00"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000ff"/>
</LinearLayout>
然后创建splashActivity,使mainlauncher = true。
[Activity(MainLauncher = true,Theme = "@style/Theme.AppCompat.Light.NoActionBar",NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
static readonly string TAG = "X:" + typeof (SplashActivity).Name;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Log.Debug(TAG,"SplashActivity.OnCreate");
// Using Layout (green and blue)
SetContentView(Resource.Layout.splash_layout);
// Using a view,SplashView below,that draws its background (yellow and red)
//SetContentView(new SplashView(this));
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
// Prevent the back button from canceling the startup process
public override void OnBackPressed() { }
// Simulates background work that happens behind the splash screen
async void SimulateStartup ()
{
Log.Debug(TAG,"Performing some startup work that takes a bit of time.");
await Task.Delay(8000); // Simulate a bit of startup work.
Log.Debug(TAG,"Startup work is finished - starting MainActivity.");
StartActivity(new Intent(Application.Context,typeof (MainActivity)));
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。