0

私がやろうとしているのは、地元のビジネスを見つけるアプリケーションを作成することです。私が行っているアクティビティは、ビジネス情報を表示します。市内に複数の店舗を持つ企業もあれば、1 つしかない企業もあります。ここに私の問題があります:ビューには、すべての要素を含むスクロールビューと、スクロールビュー内の線形レイアウトがあります。ビジネスに複数の店舗がある場合は、各店舗情報を新しいテキスト ビューに追加し、テキスト ビューをレイアウトに追加します (これはすべてコードで行います)。しかし、現時点では、レイアウトを表示すると、3 つまたは 4 つの店舗が表示されるのではなく、1 つの店舗しか表示されません。これは、表示を変更するメソッド 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>
4

2 に答える 2

3

LinearLayoutで向きを設定するのを忘れたと思いますが、水平方向に表示されています

于 2012-07-13T22:21:33.133 に答える
1

orientationのを設定するのを忘れたに違いないLinearLayout

于 2012-07-13T22:19:08.447 に答える