2012-01-06 3 views

답변

23

그렇지 않습니다. 그것은 선형 레이아웃이하는 것이 아닙니다. 대신 RelativeLayout을 사용하십시오.

ImageView view = (ImageView)findViewById(R.id.imageView); 
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams(); 
params.gravity = Gravity.LEFT; 

을하지만 당신은 RelativeLayout 대신 LinearLayout 사용해야합니다

XML

<RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello, World!" 
     android:layout_alignParentRight="true"/> 
</RelativeLayout> 

는 프로그래밍

public void makeView(Context context) { 
    RelativeLayout rl = new RelativeLayout(context); 
    TextView tv = new TextView(context); 
    tv.setText("Hello, World"); 

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams 
      (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 

    rl.addView(tv, lp); 
} 
+0

좋아요 어떻게하면 TextView를 오른쪽 정렬로 RelativeLayout에 프로그래밍 방식으로 추가 할 수 있습니까? – androiduser

+0

XML 레이아웃을 사용하고 싶지 않습니다. 데이터가 동적이기 때문에 프로그래밍 방식으로 표시하려고합니다. – androiduser

5

는이 작업을 시도 할 수 있습니다.

관련 문제