Здравствуйте,
Пусть есть класс CustomComponent с существующей для него разметкой.
Код класса CustomComponent.java:
public class CustomComponent extends LinearLayout
{
public CustomComponent(Context context, AttributeSet attrs)
{
super(context, attrs);
LayoutInflater inflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup view = (ViewGroup)inflater.inflate(R.layout.custom_component, null);
addView(view);
}
}
Код разметки custom_component.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
Этот компонент используется в некоторой деятельности, которой соответствует разметка (main.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<view
class = "com.tests.CustomComponent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Подскажите, как заставить деятельность масштабировать CustomComponent на основе параметров layout_width, layout_height, которые задаются в разметке самой деятельности (main.xml) для этого компонента? В том виде в котором он есть сейчас, он не масштабирует, как будто используется параметр wrap_content.
Спасибо.