屏幕上未显示layout_alignParentBottom到LinearLayout

时间:2018-08-24 17:22:05

标签: android xml

我正在片段化我的申请表。我的父视图是RelativeLayout,其中有ScrollView和Linearlayout。 Scrollview包含表单,而LinearLayout包含提交表单的按钮。预览屏幕在Android Studio中正确显示。但是在调试之后,Button的Linearlayout不会显示在屏幕内部。

https://imgur.com/a/4tM8fc8

XML文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".LeaveCreate">

    <ScrollView
        android:layout_alignParentTop="true"
        android:layout_above="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="vertical"
            android:layout_margin="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:text="Duration"
                android:textColor="#9e9e9e"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textSize="14sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <android.support.v7.widget.CardView
                app:cardCornerRadius="5dp"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:padding="10dp"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <EditText
                        android:id="@+id/txtFromDate"
                        android:layout_weight="2"
                        android:hint="From"
                        android:textSize="14sp"
                        android:textColor="#9e9e9e"
                        android:focusable="false"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content" />
                    <EditText
                        android:id="@+id/txtToDate"
                        android:layout_weight="2"
                        android:hint="To"
                        android:textSize="14sp"
                        android:textColor="#9e9e9e"
                        android:focusable="false"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content" />
                    <ImageView
                        android:src="@drawable/calender"
                        android:layout_weight="0.5"
                        android:layout_gravity="center_vertical"
                        android:layout_width="16dp"
                        android:layout_height="16dp" />
                </LinearLayout>
            </android.support.v7.widget.CardView>
            <TextView
                android:text="Teacher"
                android:textColor="#9e9e9e"
                android:layout_marginTop="10dp"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <android.support.v7.widget.CardView
                app:cardCornerRadius="5dp"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <com.example.acg.digimkeyparent.MultiSpinner
                    android:id="@+id/teacherSpinner"
                    android:layout_width="match_parent"
                    android:layout_height="40dp">
                </com.example.acg.digimkeyparent.MultiSpinner>
            </android.support.v7.widget.CardView>

            <TextView
                android:text="Reason"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#9e9e9e"
                android:textSize="14sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <android.support.v7.widget.CardView
                android:layout_marginTop="4dp"
                android:layout_marginBottom="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <EditText
                    android:id="@+id/txtReason"
                    android:layout_weight="1"
                    android:gravity="start|top"
                    android:padding="14dp"
                    android:minLines="5"
                    android:textSize="14sp"
                    android:textColor="#9e9e9e"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </android.support.v7.widget.CardView>
        </LinearLayout>
    </ScrollView>

        <LinearLayout
            android:id="@+id/linear"
            android:layout_margin="10dp"
            android:baselineAligned="false"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_weight="1"
                android:layout_width="0dp"
                android:gravity="center"
                android:layout_height="wrap_content">
                <android.support.v7.widget.CardView
                    android:layout_gravity="center_vertical"
                    app:cardCornerRadius="20dp"
                    android:layout_width="140dp"
                    android:layout_height="wrap_content">
                    <Button
                        android:id="@+id/btnFileSelect"
                        style="?android:attr/borderlessButtonStyle"
                        android:text="Attach"
                        android:textAllCaps="false"
                        android:textStyle="bold"
                        android:padding="7dp"
                        android:textSize="18sp"
                        android:maxLines="1"
                        android:drawableLeft="@drawable/attach"
                        android:drawableStart="@drawable/attach"
                        android:textColor="@color/appdefault"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />

                </android.support.v7.widget.CardView>
            </LinearLayout>

            <LinearLayout
                android:layout_weight="1"
                android:layout_width="0dp"
                android:gravity="center"
                android:layout_height="wrap_content">
                <android.support.v7.widget.CardView
                    android:layout_gravity="center_vertical"
                    app:cardCornerRadius="20dp"
                    android:layout_width="140dp"
                    android:layout_height="wrap_content">
                    <Button
                        android:id="@+id/btnSend"
                        style="?android:attr/borderlessButtonStyle"
                        android:text="Send"
                        android:textAllCaps="false"
                        android:textStyle="bold"
                        android:padding="7dp"
                        android:textSize="18sp"
                        android:maxLines="1"
                        android:drawableLeft="@drawable/send"
                        android:drawableStart="@drawable/send"
                        android:textColor="@color/md_white_1000"
                        android:background="@drawable/buttonbackground"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />

                </android.support.v7.widget.CardView>
            </LinearLayout>
        </LinearLayout>
        </RelativeLayout>

“我的第二个问题是我的所选选项卡”在使用“自定义视图”后未突出显示。

public class LeaveApplication extends AppCompatActivity implements LeaveCreate.OnFragmentInteractionListener,LeaveHistory.OnFragmentInteractionListener{


private SectionsPagerAdapter mSectionsPagerAdapter;


private ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_leave_application);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());


    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

    View v = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);

    TextView newTab = (TextView)  v.findViewById(R.id.text);
    newTab.setText("Create"); //tab label txt
    ImageView im1 = (ImageView) v.findViewById(R.id.image);
    im1.setImageResource(R.drawable.create_icon);
    tabLayout.getTabAt(0).setCustomView(v);

    View v1 = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);

    TextView newTab1 = (TextView)  v1.findViewById(R.id.text);
    newTab1.setText("Leave History"); //tab label txt
    ImageView im2 = (ImageView) v1.findViewById(R.id.image);
    im2.setImageResource(R.drawable.view_icon);
    tabLayout.getTabAt(1).setCustomView(v1);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i1) {

        }

        @Override
        public void onPageSelected(int i) {
            mViewPager.setCurrentItem(i,true);
            tabLayout.getTabAt(i).getCustomView().setSelected(true);
            tabLayout.setSelectedTabIndicator(R.color.md_white_1000);
        }

        @Override
        public void onPageScrollStateChanged(int i) {

        }
    });

}

@Override
public void onFragmentInteraction(Uri uri) {

}


public static class PlaceholderFragment extends Fragment {

    private static final String ARG_SECTION_NUMBER = "section_number";

    public PlaceholderFragment() {
    }

    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }
  /*
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_leave_create, container, false);

        return rootView;
    }
 */
}


public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {

        switch (position){
            case 0:
                return new LeaveCreate();
            case 1:
                return new LeaveHistory();
        }

        return null;
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 2;
    }
}
}

2 个答案:

答案 0 :(得分:0)

请为按钮的线性布局提供一个“ id”。
例如:android:id =“ @ + id / linear”
然后在滚动视图中,
    _android:layout_alignParentTop =“ true”
    android:layout_above =“ @ id / linear”     已添加。

突出显示所选标签,您可以尝试:
tabLayout.setSelectedTabIndicatorColor(//您要使用的颜色)

答案 1 :(得分:0)

android:gravity="bottom"添加到包含按钮的LinearLayout中。

要选择标签,请尝试

TabLayout.Tab tab = tabLayout.getTabAt(position);
tab.select();

tabLayout.setTabTextColors([Normal color], [Selected color]);