0

私のアプリケーションでは、5 つのボタンを含む相対レイアウトを作成しましたが、同じレイアウトを他のレイアウトで背景として使用したいと考えています。コードを試していますandroid:background+"@layout/dashboard"が、Eclipse でエラーが表示されます。スクロール ビューを実装して、ダッシュボード以外のすべての要素を呼び出すことができるように、そのレイアウトをParent Bottomとして表示したいと考えています。次のことをお知らせください。

  1. 背景として別のレイアウトを追加するにはどうすればよいですか
  2. そのレイアウトを alignParentBottom に設定するにはどうすればよいですか
  3. ダッシュボードが静的なままで、残りの要素がスクロールできるように、scrollView を変更するにはどうすればよいですか?

dashboard.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" >

    <Button
        android:id="@+id/b1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:text="Home" />

    <Button
        android:id="@+id/b2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/b1"
        android:layout_alignParentBottom="true"
        android:text="Explore" />

    <Button
        android:id="@+id/b3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="MIC" />

    <Button
        android:id="@+id/b4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/b5"
        android:layout_alignParentBottom="true"
        android:text="Msngr" />

    <Button
        android:id="@+id/b5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:text="Profile" />

</RelativeLayout>

showdashboard.xml のコード

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@layout/dashboard" >

</LinearLayout>

私が得ているエラーは次のとおりです。

ファイル C:\Users\%username%\Documents\eclipse\CustomList\res\layout\dashboard.xml の解析に失敗しました 例外の詳細は [ウィンドウ] > [ビューの表示] > [エラー ログ] に記録されます

助けてください..

4

2 に答える 2

1

ページの下部にボタンの静的ビューが必要なため、これらのボタンを線形レイアウトでラップし、残りをスクロール ビュー内に配置できます。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:id="@+id/s_view" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <!-- You can put your components here -->
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.3"
    android:orientation="horizontal" >

    <!-- your 5 buttons here -->
    <Button
        android:layout_width="match_parent"
        android:layout_height="20dp" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="20dp" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="20dp" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="20dp" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="20dp" />
</LinearLayout>

レイアウトの重みを調整することで、下部レイアウト/スクロールビューのサイズを変更できます。

複数のアクティビティに同じレイアウトを使用する場合は、個別の線形レイアウト (または必要に応じて他のレイアウト) を作成し、それらをアクティビティの scrollView に追加できます。

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_layout);
    ScrollView sv = (ScrollView) findViewById(R.id.s_view);
    LayoutInflater lInflator = getLayoutInflater();
    sv.addView(lInflator.inflate(R.layout.view_component, null));

}

ここで、s_view はスクロール ビューの ID で、コンポーネント ビューはターゲット レイアウトです。

于 2012-09-18T08:50:01.710 に答える
0

あなたが作りたいと思っているあなたの文章を通して私が得たものStatic Buttonsしかし、他のレイアウトにはScrollView

したがって、このレイアウトでこれを行うことができます

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1.0" android:background="#ffffff" android:orientation="vertical">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_weight="1.0" android:background="#ffffff" android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ffffff"
    android:orientation="vertical" android:layout_weight="1.0">
        <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0">
            ---Your Scroll Vieww Layout hereee-------
        </ScrollView>
    </LinearLayout>
</LinearLayout>

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:background="#F3F0EC" android:orientation="horizontal">

        ----your  5 Button Layout hereee-------
</LinearLayout>
</LinearLayout>
于 2012-09-18T07:18:26.513 に答える