gpt4 book ai didi

android - 设置背景图像扰乱选项卡 Activity 中的布局

转载 作者:行者123 更新时间:2023-11-30 03:28:00 25 4
gpt4 key购买 nike

我正在进行一项 Activity ,其中包含选项卡。当我不使用应用程序背景作为带有以下代码的图像时,布局工作正常。

   <style name="AppTheme" parent="AppBaseTheme">
<!-- <item name="android:background">@drawable/imagese4copy</item>
All customizations that are NOT specific to a particular API-level can go here. -->
</style>

布局看起来像:
enter image description here

当我包含背景图片时,它看起来像:
enter image description here

这是我的 MainActivity.java

public class MainActivity extends  TabActivity {
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Resources resource = getResources();
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();


Intent intentHelper = new Intent(this, Helper.class);
TabSpec tabSpecHelper = tabHost
.newTabSpec("Helper")
.setIndicator("",
resource.getDrawable(R.drawable.ic_launcher))
.setContent(intentHelper);

Intent intentRequest = new Intent(this, HelpRequest.class);
TabSpec tabSpecRequest = tabHost
.newTabSpec("HelpRequest")
.setIndicator("",
resource.getDrawable(R.drawable.ic_launcher))
.setContent(intentRequest);

Intent intentSetting = new Intent(this, SettingsActivity.class);
TabSpec tabSpecSetting = tabHost
.newTabSpec("Setting")
.setIndicator("",
resource.getDrawable(R.drawable.ic_launcher))
.setContent(intentSetting);

tabHost.addTab(tabSpecHelper);
tabHost.addTab(tabSpecRequest);
tabHost.addTab(tabSpecSetting);
tabHost.setCurrentTab(0);
}

activity_main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</TabHost>

AndroidManifest.xml:

  <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.maptest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.maptest.HelpRequest"
android:label="@string/title_activity_help_request" >
</activity>
<activity
android:name="com.example.maptest.Helper"
android:label="@string/title_activity_helper" >
</activity>
<activity
android:name="com.example.maptest.SettingsActivity"
android:label="@string/title_activity_settings" >
</activity>
</application>

</manifest>

请告诉我包含背景图片时出了什么问题,我该如何纠正。

问候,
Sourabh

最佳答案

经过研究 android dev guide我发现如果您在应用程序中应用背景图像,它将为应用程序中的所有 View 设置背景。由于 Tab 和 TextView 是一个 View ,它们也有 backgroundImage,因此会扰乱布局。

我不知道是否有更完美的解决方案可用,但将背景图像设置为 LinearLayout 或 RelativeLayout 将解决问题,但您必须将此应用于每个 xml 文件才能在所有 Activity 中获得相同的背景。

例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_darkgreyrough"
tools:context=".Overview" >

关于android - 设置背景图像扰乱选项卡 Activity 中的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17930896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com