[英]LinearLayout not displaying Items
我正在嘗試做的是添加創建一個定位一些本地業務的應用程序。 因此,我正在進行的活動將顯示業務信息。 一些企業在城市設有數家商店,而另一些僅擁有一家。 所以這是我的問題:在視圖中,我具有所有元素的滾動視圖,並且在滾動視圖內部具有線性布局。 如果該公司有一個以上的商店,我將在一個新的文本視圖中添加每個商店信息,並將文本視圖添加到布局中(這全部通過代碼完成)。 但是目前顯示布局時,它只顯示一個商店,而不顯示3或4。我做錯了什么? 這是setupViews()方法,它是顯示內容的一種變化:
private void setupViews() throws SQLException {
ImageView iv = (ImageView) findViewById(R.id.negocio_logo);
try {
iv.setImageBitmap(BitmapFactory.decodeByteArray(toShow.getImgSrc(),
0, toShow.getImgSrc().length));
} catch (NullPointerException npe) {
iv.setBackgroundColor(Color.WHITE);
}
TextView nombreEmpresa = (TextView) findViewById(R.id.nombre_empresa);
nombreEmpresa.setText(toShow.getNombre());
TextView descripcionEmpresa = (TextView) findViewById(R.id.descripcion_empresa);
descripcionEmpresa.setText(toShow.getDescripcion());
TextView direccionEmpresa = (TextView) findViewById(R.id.direccion_empresa);
direccionEmpresa.setText(toShow.getDireccion());
LinearLayout rl = (LinearLayout) findViewById(R.id.linear_layout_si);
TextView suc = (TextView) findViewById(R.id.sucursales_empresa);
sucursalDAO sDAO = new sucursalDAO();
boolean tieneSucursales = sDAO.hasSucursales(toShow.getId());
if (tieneSucursales == false) {
suc.setVisibility(View.GONE);
// sucs.setVisibility(View.GONE);
} else {
suc.setVisibility(View.VISIBLE);
ArrayList<String> sucursales = sDAO.getStringSucursales(toShow
.getId());
ArrayList<TextView> tvs = new ArrayList<TextView>();
for (int i = 0; i < sucursales.size(); i++) {
TextView tv = new TextView(this);
tv.setText(sucursales.get(i));
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tvs.add(tv);
}
for (int i = 0; i < tvs.size(); i++) {
rl.addView(tvs.get(i), i);
}
}
}
這是我認為的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widgetscroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/White"
android:orientation="vertical" >
<ImageView
android:id="@+id/negocio_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="@string/logo_negocio" />
<TextView
android:id="@+id/datos_empresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/negocio_logo"
android:background="@drawable/barra"
android:text="@string/datos_empresa"
android:textColor="@color/White" />
<TextView
android:id="@+id/nombre_empresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/datos_empresa"
android:text="@string/testing" />
<TextView
android:id="@+id/descripcion_empresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nombre_empresa"
android:text="@string/testing" />
<TextView
android:id="@+id/direccion_empresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/descripcion_empresa"
android:text="@string/testing" />
<TextView
android:id="@+id/sucursales_empresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/direccion_empresa"
android:background="@drawable/barra"
android:text="@string/sucursales"
android:visibility="gone" />
<LinearLayout
android:id="@+id/linear_layout_si"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/sucursales_empresa" >
</LinearLayout>
<TextView
android:id="@+id/contacto_empresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear_layout_si"
android:text="@string/testing" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
我認為您忘了在LinearLayout上設置方向,這表明水平
我敢打賭,您忘了設置LinearLayout
的orientation
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.