각 TextView를 클릭하면 사용자가 인신 매매에 대해 알 수 있도록 다른 레이아웃 파일로 연결되어야합니다. onCreate 메서드에서 setOnClickListener를 내 텍스트보기로 설정했습니다. 팽창시키는 것은 문제입니다. 이것이 뷰를 팽창시키는 것입니까? 나는 사람들이 setContentView를 사용하여이 조각을 사용하도록 권고 한 것을 보았다. (나는 이것을 사용해서는 안된다.) 그리고 원하는 레이아웃으로 전달하면서 레이아웃 인플레이터를 사용했다. 그러나 그것은 작동하지 않습니다. 이 코드는 어떻게 보이나요?TextView를 사용하여 펼치기 레이아웃
는 XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.piatt.worksafe.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work Safe!"
android:textSize="36sp"
android:layout_centerHorizontal="true"
android:paddingBottom="32dp"
android:id="@+id/title"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is Human Trafficing?"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:padding="16dp"
android:id="@+id/whatIsHumanTrafficing"
android:clickable="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How do I get safe labor?"
android:layout_below="@+id/whatIsHumanTrafficing"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:padding="16dp"
android:id="@+id/howDoIGetSafeLabor"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How do I check that my job/job offer is legal?"
android:layout_below="@+id/howDoIGetSafeLabor"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:padding="16dp"
android:gravity="center"
android:id="@+id/checkLegality"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How can I get help?"
android:layout_below="@+id/checkLegality"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:padding="16dp"
android:id="@+id/getHelp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About us"
android:layout_below="@+id/getHelp"
android:layout_centerHorizontal="true"
android:textSize="16sp"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:id="@+id/aboutUs"
/>
</RelativeLayout>
는 자바 클래스 : 제외
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView whatIsHumanTrafficing = (TextView) findViewById(R.id.whatIsHumanTrafficing);
whatIsHumanTrafficing.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
//What is this context, why do I need it and where does it come from?
//What is the ViewGroup, why do I need it and where does it come from?
view.inflate(Context context, R.layout.what_is_human_trafficing, ViewGroup root);
}
});
}
내가 팽창하면 (R.layout.your_layout) 다른 매개 변수가 필요합니다. @Nullable Viewgroup 루트를 알려줍니다. 도와 주셔서 감사합니다. – Davep
이전과 같은 대답입니다. 그것은'null' 일 수 있습니다 ('@ Nullable' 인자로 볼 수 있습니다) –
Null은 이제 문제가 아닙니다. 상대 레이아웃'rl'에 대한 참조를 얻었고'rl.addView (v);'보기를 추가했습니다. 앱을 실행하면 이전 레이아웃 위에 텍스트가 표시됩니다. 이 문제를 어떻게 해결할 수 있습니까? – Davep