2012-02-06 19 views
1

私は私が作成しようとしているものを... Androidのレイアウトに問題を抱えているが、これに似たものです"image1"と2を一緒にする。何もしなかったImageViews自身、上の「右」:layout_gravity:私もアンドロイドを入れて試してみました2行のAndroidのテーブルのレイアウトで問題と右揃え

<?xml version="1.0" encoding="UTF-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TableRow android:layout_gravity="left" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_column="1" 
      android:layout_gravity="left|center_vertical" 
      android:layout_span="2" 
      android:paddingRight="5dip" 
      android:textColor="#ffffffff" 
      android:textSize="13dip" /> 
    </TableRow> 

    <TableRow android:layout_gravity="right" > 

     <ImageView 
      android:layout_width="50px" 
      android:layout_height="120px" 
      android:layout_column="1" 
      android:layout_marginLeft="15dip" /> 

     <ImageView 
      android:layout_width="263px" 
      android:layout_height="150px" 
      android:layout_column="2" 
      android:layout_marginLeft="15dip" /> 
    </TableRow> 

</TableLayout> 

:とにかく、ここで

は、私は、Androidで使用しているレイアウトです。

なんらかの理由で、このAndroidレイアウトは常にラベルをインデントします(列をまたいではありません)。また、2行目のものは正しく並べることはありません。何が間違っているのか分かりません。これはAndroid 2.1です。誰でも知っていますか?

答えて

1

は、私は、レイアウトのこの種でこれを解決することになった:、別の問題は、私は何が必要に応じて、コード内のピクセルで幅/高さを設定していたことも

<?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="wrap_content" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingRight="5dip" 
     android:textColor="#ffffffff" 
     android:textSize="13dip" /> 

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

     <TableRow android:gravity="right" > 

      <ImageView 
       android:layout_width="50px" 
       android:layout_height="120px" 
       android:layout_column="1" /> 

      <ImageView 
       android:layout_width="263px" 
       android:layout_height="150px" 
       android:layout_column="2" 
       android:paddingRight="20dip" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 

、としたときにあなたは...だけでなく、列を一掃ので、コードのようなものでなければならなかったことを実行します。これは、ADT 21でADTにバグが確認され、固定されると考えられている

 abc = new TableRow.LayoutParams(myImageWidth, 
       mykpiImageHeight); 
     abc.column = 2; 
2

[OK]を次のように私の答えは次のとおりです。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

      <TextView 
       android:id="@+id/textid" 
       android:text="SOME TEXT" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="left" 
       android:paddingRight="5dip" 
       android:textColor="@color/white" 
       android:textSize="13dip" /> 

      <ImageView 
       android:src="@drawable/cloud1" 
       android:id="@+id/imageview1" 
       android:layout_alignParentRight="true" 
       android:layout_below="@id/textid" 
       android:layout_width="50dp" 
       android:layout_height="120dp" 
       android:layout_marginLeft="15dp" /> 

      <ImageView 
       android:src="@drawable/grey_bar" 
       android:layout_alignParentRight="true" 
       android:layout_below="@id/imageview1" 
       android:layout_width="263dp" 
       android:layout_height="150dp" 
       android:layout_marginLeft="15dp" /> 

</RelativeLayout> 

他のいくつかのpoitnersがあまりにもあります

  • が、これは密度の独立したピクセルのためである、PX利用DPを使用しないでください(What is the difference between "px", "dp", "dip" and "sp" on Android?を参照してください)
  • 最終製品にインラインカラーを使用しないでください。ただし、res/values/colorsに入れてください。
  • リダイレクトと一緒に追加したIDの名前を変更しますg "android:text"と "android:src"の属性を単純に表示するために使用します。
+0

これを試してみます。実際にはpxを使うのはデバイスのピクセル幅に基づいているため、これに基づいて高さ/幅を変更するので、ピクセル(デバイスピクセルに基づいてサーバー上で生成されたイメージ)が使用されます。残りはあなたが正しいですが、それは簡潔さのためにすべて取られました – automaton

+0

私はこれを試したので、実際にお互いの上にすべてを束ねました。私は別の方法で解決策を見つけました。 – automaton