我创建了一个自定义视图,我希望在活动中以横向模式显示它,但是当我从我的代码中将方向设置为横向,或者将模拟器更改为横向(使用CTRL + f11)时,我的视图是没有显示!!并且屏幕是空白的。这是我的代码
output_view.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/groubbox">
<TextView
android:id="@+id/textView_Output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/firstOutput"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"/>
<Spinner
android:id="@+id/spineer_Output"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_toLeftOf="@id/textView_Output"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:id="@+id/textView_OutputTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/outputTime"
android:layout_toLeftOf="@id/spineer_Output"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"/>
<EditText
android:id="@+id/editText_time"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_toLeftOf="@id/textView_OutputTime"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"/>
Output_View.java:
public class Output_View extends RelativeLayout{
private Context context;
private ActionbarClickedListener actionbarClickedListener;
private LayoutInflater mInflater;
private TextView tv_output, tv_outputTime;
private Spinner sp_output;
private EditText et_time;
public Output_View(Context context) {
super(context);
this.context = context;
init();
}
public Output_View(final Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
init();
}
public Output_View(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
init();
}
public void init() {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout barView = (RelativeLayout) mInflater.inflate(R.layout.output_view, null);
addView(barView);
tv_output = (TextView) findViewById(R.id.textView_Output);
tv_outputTime = (TextView) findViewById(R.id.textView_OutputTime);
et_time = (EditText) findViewById(R.id.editText_time);
sp_output = (Spinner) findViewById(R.id.spineer_Output);
}
public void setOnItemClickedListener(ActionbarClickedListener actionbarClickedListener) {
this.actionbarClickedListener = actionbarClickedListener;
}
public interface ActionbarClickedListener {
public void eventOccured(int id);
}
}
main.xml:
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_alignParentLeft = "true"
android:layout_alignParentTop = "true" >
<Kazemi.Alireza.scada.Output_View
android:id = "@+id/actionBar"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_marginLeft="10dp"/>
和主要班级:
public class Scada extends Activity
{
String result;
String[] param;
String userUrl = "http://www.hushmandsazan.com/scada/get_user.php?uname=";
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
setContentView(R.layout.test);
}
}
清单代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Kazemi.Alireza.scada"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Scada"
android:label="@string/title_activity_scada" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainMenu"
android:label="Main Menu"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="Kazemi.Alireza.scada.MainMenu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SpecificConfiguration"
android:label="Specific Configuration"
android:theme="@android:style/Theme.Dialog">
<intent-filter>
<action android:name="Kazemi.Alireza.scada.SpecificConfiguration" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".test"
android:label="test">
<intent-filter>
<action android:name="Kazemi.Alireza.scada.test" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>