KingOfNothing
@KingOfNothing

Почему свой компонент на основе LinearLayout показывается только первый раз (хотя вызван 2 раза)?

Есть компонент, который расширяет SeekBar, добавляя к нему некоторые TextView. В layout-е мне нужно разместить два компонента:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res/com.alexrudenko.general"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <com.alexrudenko.general.ui.InfoSeekBar
        android:id="@+id/seekBarMapSize"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        custom:maxText="100"
        custom:minText="50"
        custom:titleText="@string/map_size_description" />
    
     <com.alexrudenko.general.ui.InfoSeekBar
        android:id="@+id/seekBarNumberOfCountries"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        custom:maxText="20"
        custom:minText="2"
        custom:titleText="@string/number_of_countries_description" />
    
</LinearLayout>


Мой компонент com.alexrudenko.general.ui.InfoSeekBar выглядит так:
package com.alexrudenko.general.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.alexrudenko.general.R;

public class InfoSeekBar extends LinearLayout {

	// contols
	public TextView title;
	public TextView min;
	public TextView max;
	public TextView result;
	public SeekBar seekBar;
	// data
	public String titleText;
	public Integer minText;
	public Integer maxText;

	public InfoSeekBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context, attrs);
	}

	private void initView(Context context, AttributeSet attrs) {
		TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
				R.styleable.InfoSeekBar, 0, 0);
		try {
			titleText = a.getString(R.styleable.InfoSeekBar_titleText);
			minText = Integer.valueOf(a.getString(R.styleable.InfoSeekBar_minText));
			maxText = Integer.valueOf(a.getString(R.styleable.InfoSeekBar_maxText));
		} finally {
			a.recycle();
		}
		/*View v = LayoutInflater.from(context).inflate(R.layout.seek_bar, this);
		addView(v);*/
		
		LayoutInflater.from(context).inflate(R.layout.seek_bar, this);
	}

	public InfoSeekBar(Context context) {
		super(context);
		LayoutInflater.from(context).inflate(R.layout.seek_bar, this);
	}

	public InfoSeekBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context, attrs);
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		title = (TextView) this.findViewById(R.id.seekBarTextView);
		title.setText(titleText);
		min = (TextView) this.findViewById(R.id.minText);
		min.setText(String.valueOf(minText));
		max = (TextView) this.findViewById(R.id.maxText);
		max.setText(String.valueOf(maxText));
		result = (TextView) this.findViewById(R.id.resultText);
		result.setText(String.valueOf(minText));
		seekBar = (SeekBar) this.findViewById(R.id.seekBar);
		OnSeekBarChangeListener l = new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				float level = (float) progress / (float) seekBar.getMax();
				int position = (int) ((maxText - minText)*level + minText);
				result.setText(String.valueOf(position));
			}
		};
		seekBar.setMax(100);
		seekBar.setProgress(10);
		seekBar.setOnSeekBarChangeListener(l);
	}

}

и layout компонента:
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/seekBarTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <SeekBar
            android:id="@+id/seekBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/seekBarTextView" />

        <TextView
            android:id="@+id/minText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/seekBar"
            android:layout_marginLeft="10dp"
            android:text="" />
        
        <TextView
            android:id="@+id/resultText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/seekBar"
         	android:layout_centerHorizontal="true"
            android:text="" />

        <TextView
            android:id="@+id/maxText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/seekBar"
            android:layout_marginRight="10dp"
            android:text="" />
    </RelativeLayout>

</merge>


В результате отображается только компонент android:id="@+id/seekBarMapSize". В чем проблема?
  • Вопрос задан
  • 2894 просмотра
Решения вопроса 1
@bimeg
Может прсто первый занимает все пространство?

android:layout_width="match_parent"
android:layout_height="match_parent"
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы