有我的代码:
Java代码:
private void buildGrafica(final String sottotipo, final String text, String note, final int sottotipoID){
final ViewGroup mContainerView = (ViewGroup) findViewById(R.id.linear2);
//infilo la nuova birra attraverso un importazione del layout
final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.chosen_beer, mContainerView, false);
//infilo la nuova birra attraverso un importazione del layout
final ViewGroup newView2 = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.chosen_beer2, mContainerView, false);
if(sottotipo=="Titolo"){
// inserisco
((TextView) newView.findViewById(android.R.id.text1)).setText(sottotipo+" : "+text);
newView.findViewById(R.id.mod_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Deleto la riga
// perchè mContainerView è android:animateLayoutChanges settato come true,
// questa rimozione è automaticamente animata.
mContainerView.removeView(newView);
// se non c'è più nessuna riga
if (mContainerView.getChildCount() == 0) {
findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
}
}
});
}else{
((TextView) newView.findViewById(android.R.id.text1)).setText(sottotipo+" : \n\n");
newView.findViewById(R.id.mod_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Deleto la riga
// perchè mContainerView è android:animateLayoutChanges settato come true,
// questa rimozione è automaticamente animata.
mContainerView.removeView(newView);
// se non c'è più nessuna riga
if (mContainerView.getChildCount() == 0) {
findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
}
}
});
((TextView) newView2.findViewById(android.R.id.text2)).setText(text+" \n\n\nNote:\n"+note);
}
mContainerView.addView(newView, 0);
mContainerView.addView(newView2,0);
}
的活动:
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/scrollView">
<LinearLayout
android:id="@+id/linear2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:showDividers="middle"
android:divider="?android:dividerHorizontal"
android:animateLayoutChanges="true">
</LinearLayout>
</ScrollView>
Infilate activity1:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:orientation="horizontal"
android:showDividers="middle"
android:divider="?android:dividerVertical"
android:dividerPadding="8dp"
android:gravity="center">
<!-- A button that, when pressed, will delete this list item row from its container. -->
<ImageButton android:id="@+id/mod_button"
android:layout_width="48dp"
android:layout_height="match_parent"
android:src="@drawable/btn_modifica"
android:background="?android:selectableItemBackground"
android:contentDescription="@string/modify_string" />
<!-- Dummy text view that will display the name of a random country. -->
<TextView android:id="@android:id/text1"
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:clickable="true"/>
</LinearLayout>
Infilate activity2:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:orientation="vertical"
android:dividerPadding="8dp"
android:gravity="center">
<!-- Dummy text view that will display the name of a random country. -->
<TextView android:id="@android:id/text2"
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="48dp"
android:textIsSelectable="true"
android:text=""/>
</LinearLayout>
我有一个大问题,我不知道如何完全打印TEXT
((TextView) newView2.findViewById(android.R.id.text2)).setText(text+" \n\n\nNote:\n"+note);
我的布局页面应如此。
标题
IMAGE | TITLE RAW
VARIABLE TEXT很长
IMAGE | TITLE RAW
VARIABLE TEXT很长
IMAGE | TITLE RAW
VARIABLE TEXT很长 ......
---------------而不是----------------------------- ---------------------
标题
IMAGE | TITLE RAW
VARIABLE TEXT高度为图像且不可见
IMAGE | TITLE RAW
VARIABLE TEXT高度为图像且不可见
IMAGE | TITLE RAW
VARIABLE TEXT height作为图像并且不可见 ......
有人会知道说一些方法可以做我需要的吗? 提前谢谢!!!
答案 0 :(得分:0)
您使用固定高度作为父级布局,因此TextView
最大高度将限制为父级高度。
更改android:layout_height="?android:listPreferredItemHeightSmall"
到android:layout_height="wrap_content"
。
答案 1 :(得分:0)
将linearlayout的高度更改为wrap_content。