我试图将旋转器中的文本拉到尽可能远的地方。我已经在微调器的属性框中尝试了几个选项,但没有运气将文本移动到左侧。我遇到问题的微调器是spinner5。谢谢你的帮助。
这就是我用于Activity_Main.xml的内容
<Spinner
android:id="@+id/spinner5"
android:layout_width="135dp"
android:layout_height="35dp"
android:layout_gravity="start"
android:layout_marginLeft="235dp"
android:layout_marginStart="235dp"
android:layout_marginTop="-36dp"
android:background="#c3c3c3"
android:paddingTop="6dp" />
这就是我用于MainActivity.java的内容
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class MainActivity extends ActionBarActivity {
Spinner sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp=(Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence>ar=ArrayAdapter.createFromResource(this,R.array.minesite, android.R.layout.simple_expandable_list_item_1);
ar.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(ar);
sp=(Spinner)findViewById(R.id.spinner2);
ArrayAdapter<CharSequence>ar1=ArrayAdapter.createFromResource(this,R.array.AreaOfInspection,android.R.layout.simple_expandable_list_item_1);
ar.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(ar1);
sp=(Spinner)findViewById(R.id.spinner3);
ArrayAdapter<CharSequence>ar2=ArrayAdapter.createFromResource(this,R.array.Personoberving,android.R.layout.simple_expandable_list_item_1);
ar.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(ar2);
sp=(Spinner)findViewById(R.id.spinner4);
ArrayAdapter<CharSequence>ar3=ArrayAdapter.createFromResource(this,R.array.task,android.R.layout.simple_expandable_list_item_1);
ar.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(ar3);
sp=(Spinner)findViewById(R.id.spinner5);
ArrayAdapter<CharSequence>ar4=ArrayAdapter.createFromResource(this,R.array.day,android.R.layout.simple_expandable_list_item_1);
ar.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(ar4);
请参阅附图
答案 0 :(得分:0)
你只需要做这样的事情@dweidler。 您必须使用自定义布局。
创建spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textAlignment="gravity"
android:gravity="left"
/>
并在您的MainActivity.java中初始化您的ArrayAdapter
// Initializing an ArrayAdapter
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
this,R.layout.spinner_item,R.array.your_array);
spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item);
spinner.setAdapter(spinnerArrayAdapter);