我正在尝试以编程方式重新创建以下XML TextView:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="TEST3"
android:textAppearance="?android:attr/textAppearanceMedium" />
视图出现,但在左侧。重力设置为右,但TextView似乎没有“服从”。
.....为什么呢?看起来对我来说。
TextView tvFeeSum = new TextView ( getActivity () );
tvTime.setText ( "TEST3" );
tvTime.setTextAppearance ( getActivity (), android.R.style.TextAppearance_Medium );
LinearLayout.LayoutParams tvFeeSumParams = new LinearLayout.LayoutParams ( 0, LayoutParams.WRAP_CONTENT, 1f );
tvFeeSumParams.gravity = Gravity.RIGHT;
tvTime.setLayoutParams ( tvFeeSumParams );
work.addView ( tvFeeSum );
编辑:textview的父视图
<LinearLayout
android:id="@+id/work"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:weightSum="3" >
</LinearLayout>