我要做的是添加创建一个定位某些本地商家的应用程序。所以我正在做的活动显示商业信息。有些企业在城市有几个商店,有些只有一个。所以这是我的问题:在视图中我有滚动视图,包含所有元素,以及滚动视图内的线性布局。如果业务有多个商店,我将在新的文本视图中添加每个商店信息,并将文本视图添加到布局(这是通过代码完成的)。但目前显示布局,它只显示我一个商店,而不是显示我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>
答案 0 :(得分:3)
我想你忘了在LinearLayout上设置方向,它显示水平
答案 1 :(得分:1)
我打赌你忘了设置orientation
的{{1}}。