동일한 활동에 속하지 않지만 TextView가 표시되지 않는 다른 레이아웃에 표시 될 프로그래밍 방식으로 TextView를 만들려고합니다. 다음은 코드입니다 :프로그래밍 방식으로 작성된 TextView
활동 :
공용 클래스 LogActivity이 AppCompatActivity를 확장 {
LinearLayout textLayout;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_one);
LayoutInflater layoutInflater=getLayoutInflater();
View textEntryLayout=layoutInflater.inflate(R.layout.layout_two, null);
textLayout=(LinearLayout) textEntryLayout.findViewById(R.id.layout);
textView=new TextView(this);
textView.setText("TextView");
textView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
textLayout.addView(textView);
}
레이아웃 :
컨테이너layout
은, 그 높이 설정되어 다른 아이들이 있기 때문에입니다
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout"
android:background="@color/editTextBG">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/editTextFont"
android:textSize="35sp" />
<TextView
android:id="@+id/log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/editTextFont"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/editTextFont"
android:textSize="35sp" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="@color/editTextFont"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
아이 요소를 구체적으로보기를 숨기고? –
각 'LinearLayout'은'layout' 내부에 있습니다. 높이는'match_parent'로 설정 되었기 때문입니다. –