-2

Androidアプリでレイアウトを設定して、編集テキストが画面の大部分を占め、ボタンが下部になるようにします。どうすればそれを動的に行うことができますか?

スクリーンショット

テキストフィールドを残りのすべてのスペースとバランスさせたいのですが。

前もって感謝します。

この質問には回答があり、解決策が得られました。それでは、なぜ「建設的ではない」とフラグが立てられているのでしょうか。

これは、Android xml 定義で重みを与える方法の例を設定します。不快ではありませんが、この投稿に投票した人は、たとえそれがほんのわずかであっても、あらゆる種類の言い訳をして人々から血を吸うために歩き回っている吸血鬼のように感じます.

コミュニティにオープンなコミュニケーションを支持する人がいる場合は、ここに来て、荒らしによって優れた知識の収集がどのように破壊されているかを確認してください。

最後に、最後の 3 つの段落で明確に説明できていれば幸いです。

4

3 に答える 3

0

非常に簡単

<?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" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:ems="10"
        android:gravity="top|left" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>
于 2012-10-05T15:49:06.983 に答える
0

編集:

RelativeLayout layout = new RelativeLayout(this);

layout.setScrollContainer(true);    // Remove this if you would not like the soft keyboard to resize the view
LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

EditText text = new EditText(this);
text.setGravity(Gravity.TOP | Gravity.LEFT);

Button button = new Button(this);
button.setId(1000);     // The ID can be anything really

LayoutParams textParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
textParams.addRule(RelativeLayout.ABOVE, button.getId());

LayoutParams buttonParams = new LayoutParams(LayoutParams.FILL_PARENT, 100);    // I used a basic height of 100px here
buttonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

text.setLayoutParams(textParams);
button.setLayoutParams(buttonParams);

layout.setLayoutParams(layoutParams);

layout.addView(text);
layout.addView(button);

setContentView(layout);
于 2012-10-05T15:52:27.573 に答える
0

次のようなことを試してください:

<?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" >

    <EditText 
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="Enter note here"
        android:layout_weight="10"
        android:gravity="center"
        />

    <Button 
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Done"
        android:layout_weight="1"
        />

</LinearLayout>
于 2012-10-05T15:53:27.340 に答える