0

私はアンドロイドの私の研究プロジェクトのために私のインターフェースを設計しています。そこで、Facebookのようなサイドナビゲーションリストビューを追加しました。しかし、アイテムがリストビューに追加されると、水平方向の中央に配置されません..アイコンの原点とタイトルを同じ水平線で取得する必要があります。私の問題の解決策を教えてください。以下は私のコードを提供しました。私の英語について申し訳ありません。

これが私の現在のインターフェースの画像です。設定ボタンを参照してください。設定ワードは少し逆です。アイコンと設定の両方の単語が同じ行に水平に並んでいる必要があります。

画像はこちら http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash4/485944_4792129535506_1863888545_n.jpg

slide.xml- リストビューのすべてのアイテムがここに含まれています

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/item_one"
    android:icon="@drawable/settings"
    android:title="@string/item_one"
    android:top="30dp"
   >
</item>

    <item
    android:id="@+id/item_two"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_three">
</item>

<item
    android:id="@+id/item_three"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_three">
</item>
<item
    android:id="@+id/item_four"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_four">
</item>

 <item
    android:id="@+id/item_five"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_one">
</item>
<item
    android:id="@+id/item_six"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_two">
</item>
<item
    android:id="@+id/item_seven"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_three">
</item>
<item
    android:id="@+id/item_eight"
    android:icon="@drawable/ic_launcher"
    android:title="@string/item_four"
   >
</item>
</menu>

slidemenu.xml- リストビューはこちら

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

    <LinearLayout
        android:layout_width="260dip"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="#2c323f"

         >

        <ImageView
            android:id="@+id/menu_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left" 
            android:layout_marginTop="10dp"

            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            />

        <ListView
            android:id="@+id/menu_listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none"
            android:background="#2c323f"
            android:fadingEdge="none"
            android:overScrollMode="never"
            android:listSelector="#454b5d"
            android:divider="@layout/divider"
            android:dividerHeight="1sp"
            android:cacheColorHint="#2c323f"

             />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

</LinearLayout>

ここに私のアクティビティクラスがあります

package com.coboltforge.slidemenuexample;

import com.coboltforge.slidemenu.SlideMenu;
import com.coboltforge.slidemenu.SlideMenu.SlideMenuItem;
import com.coboltforge.slidemenu.SlideMenuInterface.OnSlideMenuItemClickListener;

import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnSlideMenuItemClickListener {

    private SlideMenu slidemenu;
    private final static int MYITEMID = 42;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        /*
         * There are two ways to add the slide menu: 
         * From code or to inflate it from XML (then you have to declare it in the activities layout XML)
         */
        // this is from code. no XML declaration necessary, but you won't get state restored after rotation.
//      slidemenu = new SlideMenu(this, R.menu.slide, this, 333);
        // this inflates the menu from XML. open/closed state will be restored after rotation, but you'll have to call init.
        slidemenu = (SlideMenu) findViewById(R.id.slideMenu);
        slidemenu.init(this, R.menu.slide, this, 333);

        // this can set the menu to initially shown instead of hidden
//      slidemenu.setAsShown(); 

        // set optional header image
        slidemenu.setHeaderImage(getResources().getDrawable(R.drawable.ic_launcher));

        // this demonstrates how to dynamically add menu items
        SlideMenuItem item = new SlideMenuItem();
        item.id = MYITEMID;
        item.icon = getResources().getDrawable(R.drawable.ic_launcher);
        item.label = "Dynamically added item";
        slidemenu.addMenuItem(item);

        // connect the fallback button in case there is no ActionBar
        Button b = (Button) findViewById(R.id.buttonMenu);
        b.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                slidemenu.show();
            }
        });

    }



    public void onSlideMenuItemClick(int itemId) {

        switch(itemId) {
        case R.id.item_one:
            Toast.makeText(this, "Item one selected", Toast.LENGTH_SHORT).show();
            break;
        case R.id.item_two:
            Toast.makeText(this, "Item two selected", Toast.LENGTH_SHORT).show();
            break;
        case R.id.item_three:
            Toast.makeText(this, "Item three selected", Toast.LENGTH_SHORT).show();
            break;
        case R.id.item_four:
            Toast.makeText(this, "Item four selected", Toast.LENGTH_SHORT).show();
            break;
        case MYITEMID:
            Toast.makeText(this, "Dynamically added item selected", Toast.LENGTH_SHORT).show();
            break;
        }

    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
        case android.R.id.home: // this is the app icon of the actionbar
            slidemenu.show();
            break;
        }
        return super.onOptionsItemSelected(item);
    }


}
4

2 に答える 2

0

設定ワードは少し逆です。アイコンと設定の両方の単語が同じ行に水平に並んでいる必要があります

このライブラリを使用していると思います。問題は、スライド メニュー アダプターの行ビューに使用されるレイアウト ファイルにアクセスして変更できないことです。ただし、ライブラリのコード (非常に少数のファイルで構成されている) をコピーしてプロジェクトに直接配置すると、これを簡単に解決できます。次に、次のslidemenu_listitem.xmlようにファイルを変更します。

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

    <ImageView
        android:id="@+id/menu_icon"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginBottom="10dip"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="5dip"
        android:layout_marginTop="10dip" />

    <TextView
        android:id="@+id/menu_label"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_marginBottom="10dip"
        android:layout_marginTop="10dip"

        android:textSize="24dp" />

</LinearLayout>

もちろん、ライブラリを変更する方法をユーザーにいつでも機能要求することができるので、ライブラリに独自のレイアウト ファイルを挿入することができます (そしてそれが起こるのを待ちます)。

于 2013-01-27T13:08:50.397 に答える
0

を使用できます。

android:gravity="center" (or top/bottom/left/right depending your needs)

あなたのテキストビューのあなたが望む場所にテキストを揃えるために。

layout_gravity は、親内のビューまたはレイアウトの重力 (配置) を設定します。線形レイアウト内にテキスト ビューがある場合、テキスト ビューの layout_gravity を設定すると、レイアウト内での配置が変更されます。重力は、それが適用されるビューまたはレイアウトのコンテンツの配置を設定します。(テキスト ビュー内の) テキストを左揃え、中央揃え、または右揃えにする場合は、テキスト ビューの重力属性を変更します。

から: http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/

于 2013-01-27T12:56:28.127 に答える