2016-12-09 1 views
0

Tablerow에서 4 개의 이미지 뷰가 있습니다. 그것들은 layout_weight 명령을 통해 크기가 조정됩니다. 나는 지금이 Imageviews에 쓸 필요가있다. 상대 레이아웃을 사용하여 정렬 된 의미를 사용하지 않고이 작업을 수행 할 수 있습니까?Imageview에서 이미지 뷰를 사용하여 이미지 뷰를 배치합니다. layout_weight를 사용합니다.

TableRow.LayoutParams params = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f); 
    TableRow.LayoutParams params1 = new TableRow.LayoutParams(0,ViewGroup.LayoutParams.WRAP_CONTENT,1.2f); 
    TableRow.LayoutParams params2 = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 2.4f); 
    TableRow.LayoutParams params3 = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 3.6f); 
    TableRow.LayoutParams params4 = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 4.8f); 


     TableRow tableRow = new TableRow(this); 
     tableRow.setLayoutParams(params); 



     ImageView rank = new ImageView(this); 
     rank.setAdjustViewBounds(true); 
     rank.setLayoutParams(params1); 
     rank.setImageResource(R.drawable.whitebutton); 

     Layout[i] = new ImageView(this); 
     Layout[i].setLayoutParams(params2); 
     Layout[i].setImageResource(R.drawable.width2); 
     Layout[i].setAdjustViewBounds(true); 


     Layout[i+10] = new ImageView(this); 
     Layout[i+10].setLayoutParams(params3); 
     Layout[i+10].setImageResource(R.drawable.width3); 
     Layout[i+10].setAdjustViewBounds(true); 


     Layout[i+20] = new ImageView(this); 
     Layout[i+20].setLayoutParams(params4); 
     Layout[i+20].setImageResource(R.drawable.width4); 
     Layout[i+20].setAdjustViewBounds(true); 


     tableRow.addView(rank); 
     tableRow.addView(Layout[i]); 
     tableRow.addView(Layout[i+10]); 
     tableRow.addView(Layout[i+20]); 
     t.addView(tableRow); 

이 내가 만들려는 인터페이스입니다 :

이 순간에 내 코드입니다 interface

잘은 또한,

을의 실제 최고 점수와 같은 크기의 4 개 장의 사진

답변

0

TextView 대신 사용 ImageView

<TextView 
    android:layout_width="300dp" 
    android:layout_height="200dp" 
    android:id="@+id/b1" 
    android:text="hai every one !" 
    android:textColor="#ffff" 
    android:textSize="20sp" 
    android:gravity="center" 
    android:background="#EF5350" 
    android:padding="20dp" 
    android:drawableLeft="@mipmap/ic_launcher" 
    android:drawableTop="@mipmap/ic_launcher" 
    android:drawableRight="@mipmap/ic_launcher" 
    android:drawableBottom="@mipmap/ic_launcher" 
    android:layout_centerInParent="true"/> 

여기에서 텍스트, 배경 및 4 개의 드로어 블을 사용할 수 있습니다. paddingLeft, paddingTop, paddingRight 및 paddingBottom을 사용하여 드로어 블을 정렬 할 수 있습니다. RelativeLayout

내부 대신 ImageView .Add TextView

수술실

사용 RelativeLayout는 내가 첫 번째 방법을 선호합니다.

+0

하지만이 경우에는 필요한 무게 명령을 잃어 버렸습니다. – TimWalter

+0

나에게 스크린 샷을주세요 !! 코드 !! –

관련 문제