4

whatsupのようなアプリをやっています。私の質問はインターフェースについてです。メッセージ desc を取得して解析できます。その後、プログラムでレイアウトを追加できますが、常に同じ座標を書いています。tv.setTopを試しtv.layout(l, t, r, b)てみましたが、うまくいきません。

問題はどこにありますか?

  bubbleLayout=(RelativeLayout)findViewById(R.id.layoutbubble);

  for(int i=0;i<msgid.length;i++){
      RelativeLayout relativeLayout = new RelativeLayout(this);
      RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT,
              RelativeLayout.LayoutParams.FILL_PARENT);

      // Creating a new TextView
      TextView tv = new TextView(this);
      tv.setText(msgdesc[i]);
      tv.setTop(20);        

      // Defining the layout parameters of the TextView
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.WRAP_CONTENT,
              RelativeLayout.LayoutParams.WRAP_CONTENT);
      lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

      // Setting the parameters on the TextView
      tv.setLayoutParams(lp);

      // Adding the TextView to the RelativeLayout as a child
      bubbleLayout.addView(tv);

私のXMLファイル:

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

    <RelativeLayout
        android:layout_width="1300dip"
        android:layout_height="80dip"
        android:background="#084B8A" >

        <TextView
            android:id="@+id/messagetitle"
            android:layout_width="wrap_content"
            android:layout_height="90dip"
            android:layout_centerInParent="true"
            android:layout_marginTop="30dip"
            android:textColor="#ffffff"
            android:textSize="12pt" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layoutbubble"
        android:layout_width="1300dip"
        android:layout_height="500dip"
        android:layout_marginTop="10dip" >
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="1300dip"
        android:layout_height="80dip"
        android:layout_marginTop="10dip" >

        <EditText
            android:id="@+id/replytext"
            android:layout_width="1000dip"
            android:layout_height="90dip"
            android:layout_marginLeft="10dip" />

        <Button
            android:id="@+id/sendbutton"
            android:layout_width="200dip"
            android:layout_height="90dip"
            android:layout_marginLeft="1050dp"
            android:background="#084B8A"
            android:text="Send"
            android:textColor="#ffffff"
            android:textSize="12pt" />
    </RelativeLayout>

</LinearLayout>

スクリーンショット

4

2 に答える 2

3

問題を解決RelativeLayoutしました.xmlでに変更しLinearLayoutました

<LinearLayout
        android:id="@+id/layoutbubble"
        android:layout_width="1300dip"
        android:layout_height="500dip"
        android:layout_marginTop="10dip"
        android:orientation="vertical">
</LinearLayout>

そして、私のコードを次のように変更します。

bubbleLayout=(LinearLayout)findViewById(R.id.layoutbubble);
for(int i=0;i<msgid.length;i++){  
    // Creating a new TextView
    TextView tv = new TextView(this);
    tv.setText(msgdesc[i]);
    tv.setPadding(30, 10, 0, 0);         
    bubbleLayout.addView(tv);         
}

それだ。

于 2013-01-21T09:20:17.273 に答える
2

RelativeLayout または通常の LinearLayout を使用していると思いますか?

LinearLayout を使用してみてくださいandroid:orientation="vertical"

于 2013-01-18T12:38:07.270 に答える