[英]Android- how to get a scroll view to take up the full width of the screen?
[英]android - ToolBar widget did not take full width
我現在正在學習android,現在還很新,對ToolBar感到困惑,一直在閱讀其他所有內容,但似乎對我不起作用。 在MainActivity中,工具欄工作正常,工具欄上的按鈕不帶填充物就移到右側,但是當我移至其他活動時,按鈕沒有放置在右側,就好像那里有填充物一樣,
這是我的toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#5f0e92"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
我的第二項活動
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/toolbar"
android:id="@+id/include"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="@+id/scrollOff"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_above="@+id/TotShow"
android:layout_below="@+id/include"
android:visibility="gone">
<TableLayout
android:layout_width="match_parent" android:layout_height="32dp"
android:gravity="center_horizontal"
android:id="@+id/tableLayoutOff"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/TotShow"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
我把這個onCreate函數
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- - - - - - 編輯 - - - - - - - -
忘記了按鈕/切換toggle.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="right">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:background="@android:drawable/ic_menu_help"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/actionbar_service_toggle"
android:layout_toStartOf="@+id/actionbar_service_toggle" />
<ToggleButton
android:id="@+id/actionbar_service_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="inchi"
android:textOn="milli"
android:gravity="right"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
customview:
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.togle);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM);
在我的MainActivity中,這項工作完全正常
在第二個活動中似乎有正確的填充
我解決了這個問題,對此感到非常抱歉,似乎我對代碼做了一些愚蠢的事情,我不小心保留了以下代碼:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present..
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
好吧,目前我正在學習這個android,所以我只是從main活動中復制粘貼代碼,並且在mainactivity中禁用添加菜單后,我忘了在第二個活動中禁用它,因此右側有一個菜單是透明的,當我嘗試單擊它時,按鈕起作用,這就是我意識到自己的錯誤的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.