【问题标题】:Menubar like ES Explorer in android类似 ES Explorer 的菜单栏在 android
【发布时间】:2015-05-10 06:15:25
【问题描述】:

我想实现这个:

我试图做的是并排添加一个按钮和微调器,用户界面看起来很糟糕。我怎样才能实现这样的用户界面(红色标记)?提前致谢。

到目前为止我所尝试的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <Spinner
        android:id="@+id/storageDirectory"
        android:layout_width="0dp"
        android:layout_height="45dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:background="@android:drawable/btn_dropdown"
        android:spinnerMode="dropdown"
        android:textSize="12dip"
        android:layout_weight=".5"/>
        <Button
            android:id="@+id/frame"
            android:layout_width="0dp"
            android:layout_height="45dp"
            android:layout_marginRight="5dp"
            android:textSize="12dip"
            android:layout_marginTop="5dp"
            android:layout_weight=".5"/>
</LinearLayout>
    <ListView
        android:id="@+id/fileList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

【问题讨论】:

    标签: android xml file user-interface


    【解决方案1】:

    建议将ActionBar 替换为ToolBar。看看这里:https://developer.android.com/reference/android/support/v7/widget/Toolbar.html - 你要的只是SpinnerTextViewImageView

    它可能看起来像这样:

    XML 布局:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@android:color/holo_red_light"
            android:paddingBottom="0dp"
            android:paddingTop="0dp">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:weightSum="1.1">
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:gravity="center"
                    android:text="/"
                    android:textSize="22sp" />
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="0.1"
                    android:adjustViewBounds="true"
                    android:scaleType="fitCenter"
                    android:src="@drawable/ic_arrow" />
    
                <Spinner
                    android:id="@+id/spinner"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_weight="0.5" />
    
            </LinearLayout>
    
        </android.support.v7.widget.Toolbar>
    
    </RelativeLayout>
    

    MainActivity 类:

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            Spinner spinner = (Spinner) findViewById(R.id.spinner);
            spinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, new String[]{"Test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6", "Test 7", "Test 8", "Test 9", "Test 10"}));
        }
    }
    

    希望这会有所帮助。关键思想是使用ToolBar,您可以完全按照您想要的方式进行自定义:-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      相关资源
      最近更新 更多