无法使两个视图平等占据屏幕

时间:2016-03-26 13:03:19

标签: android android-tablelayout

我使用以下代码创建包含文本视图和微调器的表格布局。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow>

        <TextView
            android:id="@+id/lblListHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="20dp"
            android:layout_weight="1"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:text="Form"
            android:singleLine="true"
            android:textColor="#000" />
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:drawable/btn_dropdown"
            android:spinnerMode="dropdown"
            android:entries="@array/action"/>

    </TableRow>
</TableLayout>

问题是文本视图和微调器的宽度不相等。当文本视图的大小很大时,微调器的大小变小。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

将两者的width更改为零,而不是wrap_content

android:layout_width="0dp"

当您同时使用weightwidth时,width属性将覆盖weight

答案 1 :(得分:1)

试试这个 -

@Override
public void onClick(View v) {
    if (v.getId() == R.id.ButtonTestPlayPause) {
        /** ImageButton onClick event handler. Method which start/pause mediaplayer playing */
        try {
            mediaPlayer.setDataSource(editTextSongURL.getText().toString()); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source
            mediaPlayer.prepare(); // you must call this method after setup the datasource in setDataSource method. After calling prepare() the instance of MediaPlayer starts load data from URL to internal buffer.
        } catch (Exception e) {
            e.printStackTrace();
        }

        mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the song length in milliseconds from URL

        if (!mediaPlayer.isPlaying()) {
            mediaPlayer.start();
            buttonPlayPause.setImageResource(R.drawable.button_pause);
        } else {
            mediaPlayer.pause();
            buttonPlayPause.setImageResource(R.drawable.button_play);
        }

        primarySeekBarProgressUpdater();
    }
}

答案 2 :(得分:1)

尝试使用重量属性和总重量。