Если у вас будет много котировок, я предлагаю вам использовать RecyclerView
вместе с RecyclerView.Adapter
.LinearLayout
может замедлить ваше приложение.
Но если у вас не так много кавычек или вы действительно хотите использовать LinearLayout
.Вы можете создать listitem_quote.xml
, содержащий вашу цитату и сначала 4 кнопки.
А затем использовать пустой LinearLayout
в своем activity.xml
, как это.
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/myLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
В своей деятельностиinflate()
за каждые кавычки.И добавьте их в свой макет.
onCreate(...){
setContentView(R.layout.activity_main);
myLinearLayout = (LinearLayout) findViewById(R.id.myLinearLayout);
LayoutInflater layoutInflater = LayoutInflater.from(this);
for(...){ // for every quote
// create a view for quote contains buttons
View quoteView = layoutInflater.inflate(R.layout.listitem_quote, null);
TextView tvQuote = quoteView.findViewById(...);
tvQuote.setText(...);
Button btn1 = quoteView.findViewById(...);
btn1.setOnclickListener(...);
myLinearLayout.addView(quote);// add to Linearlayout
}
}
Это поможет.
Однако я все же предлагаю вам использовать RecyclerView
вместо этого.Вы можете найти много примеров в Интернете.Это выглядит сложнее, но полезно.