gpt4 book ai didi

java - float 操作按钮菜单不随标题滚动

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:53 25 4
gpt4 key购买 nike

我目前正在编写一个小应用程序,并尝试集成 Google 的“ Material 设计”。

我在我的应用程序中使用 github 的 float 操作菜单按钮库,我有一些担心。

与单个按钮不同,菜单生成更大的 View 。我把菜单放在 fab 标题下。但代码看起来不太好。

我希望在我的标题下正确调出菜单工厂(我使用 CollapsingToolbarLayout)。菜单跟随滚动。但我被困在这里了。

我的问题是如何将菜单 fab 放在标题和卡片 View 之间,以及如何使用折叠工具栏滚动 fab 菜单。

提前谢谢您。

我的布局:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/drawerlayout1">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorlayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:expandedTitleMarginStart="70dp">

<android.support.design.widget.AppBarLayout
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_width="fill_parent"
android:id="@+id/appbarlayout"
android:layout_height="230dp">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/CollapsingToolbarLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/console_font"/>

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:title="test"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:clickable="true"
app:layout_collapseMode="pin"
android:minHeight="?attr/actionBarSize"/>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight=".1" >

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">

<LinearLayout
android:layout_alignParentBottom="true"
android:id="@+id/fragmentContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp">

<TextView
android:textColor="@android:color/holo_blue_light"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Console"
android:id="@+id/textView5" />

<Spinner
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_gravity="center_horizontal" />

<View style="@style/Divider"/>

<TextView
android:textColor="@android:color/holo_blue_light"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Etat"
android:id="@+id/textView2" />

<Spinner
android:layout_marginTop="10dp"
android:entries="@array/etat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/spinner2" />

<View style="@style/Divider"/>

<TextView
android:textColor="@android:color/holo_blue_light"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Région"
android:id="@+id/textView6" />

<Spinner
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/localisation"
android:id="@+id/spinner3" />

<View style="@style/Divider"/>

<TextView
android:textColor="@android:color/holo_blue_light"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Contenu"
android:id="@+id/textView3" />

<Spinner
android:layout_marginTop="10dp"
android:entries="@array/contenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner4"
android:layout_gravity="center_horizontal" />

</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_weight=".1" >

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view2"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/fragmentContainer2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp">

<EditText
android:textColor="@android:color/holo_blue_light"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginBottom="10dp"
android:hint="Ecrire un commentaire" />
</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

</LinearLayout>

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

<com.github.clans.fab.FloatingActionMenu
android:id="@+id/menu_down"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_alignParentRight="true"
android:layout_marginTop="185dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:elevation="6dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
app:layout_anchor="@id/image"
app:layout_anchorGravity="bottom|right|end"
fab:menu_openDirection="down">

<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_size="mini"
fab:fab_label="Menu item 1" />

<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_size="mini"
fab:fab_label="Menu item 2" />

</com.github.clans.fab.FloatingActionMenu>

</android.support.design.widget.CoordinatorLayout>

我的代码 fragment :

    public class ConsoleSql extends AppCompatActivity  {

private JvAdapter mDbHelper;
TextView Titre;
Spinner spin_console;
Spinner spin_etat;
Spinner spin_region;
Spinner spin_contenu;
EditText commentaire;
String value;
CollapsingToolbarLayout collapsingToolbarLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customconsole);
Toolbar myToolbar = (Toolbar) findViewById(toolbar);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.CollapsingToolbarLayout1);

myToolbar.setTitle("Ajout console");
setSupportActionBar(myToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);

spin_console = (Spinner) findViewById(R.id.spinner);
spin_etat = (Spinner) findViewById(R.id.spinner2);
spin_region = (Spinner) findViewById(R.id.spinner3);
spin_contenu = (Spinner) findViewById(R.id.spinner4);
commentaire = (EditText) findViewById(R.id.editText);


Bundle extras = getIntent().getExtras();
if (extras != null) {
value = extras.getString("constructeur");
int arryid = this.getResources().getIdentifier(value, "array", this.getPackageName());
collapsingToolbarLayout.setTitle("Console "+value);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arryid, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin_console.setAdapter(adapter);

}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.consolemenu, menu);

return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_save) {
mDbHelper = new JvAdapter(this);
mDbHelper.open();
//do some stuffs...
return true;
}

return super.onOptionsItemSelected(item);
}

最佳答案

将layout_anchor更改为“appbarlayout”而不是“image”

<com.github.clans.fab.FloatingActionMenu
android:id="@+id/menu_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="6dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
app:layout_anchor="@id/appbarlayout"
app:layout_anchorGravity="bottom|end"
fab:menu_openDirection="down">


</com.github.clans.fab.FloatingActionMenu>

关于java - float 操作按钮菜单不随标题滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38478513/

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