エミュレータで唯一のものであれば、うまく動作するカスタムScrollViewがあります。カスタムスクロールビューが表示されない
public class Timeline2Activity extends Activity {
private TimelineView tlv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tlv = new TimelineView(this);
setContentView(tlv);
}
}
をしかし、私は最初にウィジェットを追加する場合、それは表示されない:
例えば、これは正常に動作します。私は2日間検索し実験したが、何も働かない。ここで
は、カスタムScrollViewのクラス宣言です:
public class TimelineView extends ScrollView implements OnTouchListener {
そしてここでは、コンストラクタは、次のとおりです。ここで
public TimelineView(Context context) {
super(context);
this.setOnTouchListener(this);
setVisibility(VISIBLE);
}
//the following constructor is needed to inflate the view from XML
public TimelineView(Context context, AttributeSet ats) {
super(context,ats);
this.setOnTouchListener(this);
setVisibility(VISIBLE);
}
はmain.xmlです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/zoomall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom All" />
<Button
android:id="@+id/zoomout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="@+id/zoomin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Spinner
android:id="@+id/category_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/category_prompt"
/>
</LinearLayout>
<com.projects.timeline2.TimelineView
android:id="@+id/timeline_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
そして、ここにメインプログラム:
public class Timeline2Activity extends Activity {
private TimelineView tlv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//tlv = new TimelineView(this);
//setContentView(tlv);
setContentView(R.layout.main);
Spinner spinnerCategory = (Spinner) findViewById(R.id.category_spinner);
ArrayAdapter<CharSequence> adapterCategory = ArrayAdapter.createFromResource(
this, R.array.categories, android.R.layout.simple_spinner_item);
adapterCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCategory.setAdapter(adapterCategory);
spinnerCategory.setOnItemSelectedListener(new MyOnItemSelectedListener());
//TimelineView tlv = (TimelineView) findViewById(R.id.timeline_view);
//ViewGroup container = (ViewGroup) findViewById(R.id.container);
//container.addView(tlv);
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "The selection is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
}
コメントアウトされた行は、私が試したものですが、うまくいきませんでした。
このコードでは、3つのボタンと1つのスピンナーが、上の横の行に正しく配置されています。しかしTimelineViewはその下に表示されません。私は、私が入れたLogCatでデバッグ出力を見ることができるので、TimelineViewが動作していることを知っています。
私は知恵があります。これは一般的な基本的な必要性のように思え、確かにGoogleのチュートリアルに値する。
あなたは何が起こっているかについての詳細を教えてください。 – JoxTraex